MCPcopy Create free account
hub / github.com/cli/cli / NewCmdList

Function NewCmdList

pkg/cmd/event/subscription/list/list.go:31–66  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*ListOptions) error)

Source from the content-addressed store, hash-verified

29}
30
31func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command {
32 opts := &ListOptions{
33 IO: f.IOStreams,
34 Config: f.Config,
35 EventClient: shared.EventClientFunc(f),
36 Now: time.Now,
37 }
38
39 cmd := &cobra.Command{
40 Use: "list",
41 Short: "List event subscriptions (preview)",
42 Example: heredoc.Doc(`
43 # List your subscriptions
44 $ gh event subscription list
45
46 # Print the ID and resource of each subscription
47 $ gh event subscription list --json id,resourceUrl --jq '.[] | [.id, .resourceUrl] | @tsv'
48 `),
49 Aliases: []string{"ls"},
50 Args: cobra.NoArgs,
51 RunE: func(cmd *cobra.Command, args []string) error {
52 if opts.Limit < 1 {
53 return cmdutil.FlagErrorf("invalid limit: %v", opts.Limit)
54 }
55
56 if runF != nil {
57 return runF(opts)
58 }
59 return listRun(cmd.Context(), opts)
60 },
61 }
62
63 cmd.Flags().IntVarP(&opts.Limit, "limit", "L", 30, "Maximum number of subscriptions to list")
64 cmdutil.AddJSONFlags(cmd, &opts.Exporter, client.SubscriptionFields)
65 return cmd
66}
67
68func listRun(ctx context.Context, opts *ListOptions) error {
69 cfg, err := opts.Config()

Callers 1

TestNewCmdListFunction · 0.70

Calls 4

EventClientFuncFunction · 0.92
FlagErrorfFunction · 0.92
AddJSONFlagsFunction · 0.92
listRunFunction · 0.70

Tested by 1

TestNewCmdListFunction · 0.56