MCPcopy Index your code
hub / github.com/cli/cli / NewCmdList

Function NewCmdList

pkg/cmd/org/list/list.go:23–57  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*ListOptions) error)

Source from the content-addressed store, hash-verified

21}
22
23func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command {
24 opts := ListOptions{
25 IO: f.IOStreams,
26 Config: f.Config,
27 HttpClient: f.HttpClient,
28 }
29
30 cmd := &cobra.Command{
31 Use: "list",
32 Args: cobra.MaximumNArgs(1),
33 Short: "List organizations for the authenticated user.",
34 Example: heredoc.Doc(`
35 # List the first 30 organizations
36 $ gh org list
37
38 # List more organizations
39 $ gh org list --limit 100
40 `),
41 Aliases: []string{"ls"},
42 RunE: func(cmd *cobra.Command, args []string) error {
43 if opts.Limit < 1 {
44 return cmdutil.FlagErrorf("invalid limit: %v", opts.Limit)
45 }
46
47 if runF != nil {
48 return runF(&opts)
49 }
50 return listRun(&opts)
51 },
52 }
53
54 cmd.Flags().IntVarP(&opts.Limit, "limit", "L", 30, "Maximum number of organizations to list")
55
56 return cmd
57}
58
59func listRun(opts *ListOptions) error {
60 httpClient, err := opts.HttpClient()

Callers 1

TestNewCmdListFunction · 0.70

Calls 2

FlagErrorfFunction · 0.92
listRunFunction · 0.70

Tested by 1

TestNewCmdListFunction · 0.56