forked from operator-framework/operator-registry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd.go
107 lines (92 loc) · 2.78 KB
/
cmd.go
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package list
import (
"os"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/operator-framework/operator-registry/alpha/action"
)
const humanReadabilityOnlyNote = `NOTE: This is meant to be used for convenience and human-readability only. The
CLI and output format are subject to change, so it is not recommended to depend
on the output in any programs or scripts. Use the "render" subcommand to do
more complex processing and automation.`
func NewCmd() *cobra.Command {
list := &cobra.Command{
Use: "list",
Short: "List contents of an index",
Long: `The list subcommands print the contents of an index.
` + humanReadabilityOnlyNote,
}
list.AddCommand(newPackagesCmd(), newChannelsCmd(), newBundlesCmd())
return list
}
func newPackagesCmd() *cobra.Command {
logger := logrus.New()
return &cobra.Command{
Use: "packages <indexRef>",
Short: "List packages in an index",
Long: `The "channels" command lists the channels from the specified index.
` + humanReadabilityOnlyNote,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
lp := action.ListPackages{IndexReference: args[0]}
res, err := lp.Run(cmd.Context())
if err != nil {
logger.Fatal(err)
}
if err := res.WriteColumns(os.Stdout); err != nil {
logger.Fatal(err)
}
return nil
},
}
}
func newChannelsCmd() *cobra.Command {
logger := logrus.New()
return &cobra.Command{
Use: "channels <indexRef> [packageName]",
Short: "List package channels in an index",
Long: `The "channels" command lists the channels from the specified index and package.
` + humanReadabilityOnlyNote,
Args: cobra.RangeArgs(1, 2),
RunE: func(cmd *cobra.Command, args []string) error {
lc := action.ListChannels{IndexReference: args[0]}
if len(args) > 1 {
lc.PackageName = args[1]
}
res, err := lc.Run(cmd.Context())
if err != nil {
logger.Fatal(err)
}
if err := res.WriteColumns(os.Stdout); err != nil {
logger.Fatal(err)
}
return nil
},
}
}
func newBundlesCmd() *cobra.Command {
logger := logrus.New()
return &cobra.Command{
Use: "bundles <indexRef> <packageName>",
Short: "List package bundles in an index",
Long: `The "bundles" command lists the bundles from the specified index and package.
Bundles that exist in multiple channels are duplicated in the output (one
for each channel in which the bundle is present).
` + humanReadabilityOnlyNote,
Args: cobra.RangeArgs(1, 2),
RunE: func(cmd *cobra.Command, args []string) error {
lb := action.ListBundles{IndexReference: args[0]}
if len(args) > 1 {
lb.PackageName = args[1]
}
res, err := lb.Run(cmd.Context())
if err != nil {
logger.Fatal(err)
}
if err := res.WriteColumns(os.Stdout); err != nil {
logger.Fatal(err)
}
return nil
},
}
}