MCPcopy
hub / github.com/cli/cli / NewCmdList

Function NewCmdList

pkg/cmd/project/list/list.go:32–76  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(config listConfig) error)

Source from the content-addressed store, hash-verified

30}
31
32func NewCmdList(f *cmdutil.Factory, runF func(config listConfig) error) *cobra.Command {
33 opts := listOpts{}
34 listCmd := &cobra.Command{
35 Use: "list",
36 Short: "List the projects for an owner",
37 Example: heredoc.Doc(`
38 # List the current user's projects
39 $ gh project list
40
41 # List the projects for org github including closed projects
42 $ gh project list --owner github --closed
43 `),
44 Aliases: []string{"ls"},
45 RunE: func(cmd *cobra.Command, args []string) error {
46 client, err := client.New(f)
47 if err != nil {
48 return err
49 }
50
51 URLOpener := func(url string) error {
52 return f.Browser.Browse(url)
53 }
54
55 config := listConfig{
56 client: client,
57 opts: opts,
58 URLOpener: URLOpener,
59 io: f.IOStreams,
60 }
61
62 // allow testing of the command without actually running it
63 if runF != nil {
64 return runF(config)
65 }
66 return runList(config)
67 },
68 }
69 listCmd.Flags().StringVar(&opts.owner, "owner", "", "Login of the owner")
70 listCmd.Flags().BoolVarP(&opts.closed, "closed", "", false, "Include closed projects")
71 listCmd.Flags().BoolVarP(&opts.web, "web", "w", false, "Open projects list in the browser")
72 cmdutil.AddFormatFlags(listCmd, &opts.exporter)
73 listCmd.Flags().IntVarP(&opts.limit, "limit", "L", queries.LimitDefault, "Maximum number of projects to fetch")
74
75 return listCmd
76}
77
78func runList(config listConfig) error {
79 if config.opts.web {

Callers 1

TestNewCmdlistFunction · 0.70

Calls 4

NewFunction · 0.92
AddFormatFlagsFunction · 0.92
runListFunction · 0.70
BrowseMethod · 0.65

Tested by 1

TestNewCmdlistFunction · 0.56