-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlist_packages.go
More file actions
78 lines (63 loc) · 1.82 KB
/
list_packages.go
File metadata and controls
78 lines (63 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package cmd
import (
"fmt"
"github.com/codesphere-cloud/oms/internal/portal"
"github.com/codesphere-cloud/oms/internal/util"
"github.com/codesphere-cloud/cs-go/pkg/io"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/spf13/cobra"
)
type ListBuildsCmd struct {
cmd *cobra.Command
Opts ListBuildsOpts
TableWriter util.TableWriter
}
type ListBuildsOpts struct {
GlobalOptions
Internal bool
}
func (c *ListBuildsCmd) RunE(_ *cobra.Command, args []string) error {
p := portal.NewPortalClient()
packages, err := p.ListCodesphereBuilds()
if err != nil {
return fmt.Errorf("failed to list codesphere packages: %w", err)
}
c.PrintPackagesTable(packages)
return nil
}
func AddListPackagesCmd(list *cobra.Command, opts GlobalOptions) {
builds := ListBuildsCmd{
cmd: &cobra.Command{
Use: "packages",
Short: "List available packages",
Long: io.Long(`List packages available for download via the OMS portal.`),
},
Opts: ListBuildsOpts{GlobalOptions: opts},
TableWriter: util.GetTableWriter(),
}
builds.cmd.RunE = builds.RunE
builds.cmd.Flags().BoolVarP(&builds.Opts.Internal, "list-internal", "i", false, "List internal packages")
_ = builds.cmd.Flags().MarkHidden("list-internal")
list.AddCommand(builds.cmd)
}
func (c *ListBuildsCmd) PrintPackagesTable(packages portal.CodesphereBuilds) {
c.TableWriter.AppendHeader(table.Row{"Int", "Version", "Build Date", "Hash", "Artifacts"})
for _, build := range packages.Builds {
if !c.Opts.Internal && build.Internal {
continue
}
int := ""
if build.Internal {
int = "*"
}
artifacts := ""
for i, art := range build.Artifacts {
if i > 0 {
artifacts += ", "
}
artifacts = artifacts + art.Filename
}
c.TableWriter.AppendRow(table.Row{int, build.Version, build.Date, build.Hash, artifacts})
}
c.TableWriter.Render()
}