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

Function NewCmdList

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

Source from the content-addressed store, hash-verified

40}
41
42func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command {
43 opts := ListOptions{
44 IO: f.IOStreams,
45 Config: f.Config,
46 HttpClient: f.HttpClient,
47 Now: time.Now,
48 }
49
50 var (
51 flagPublic bool
52 flagPrivate bool
53 )
54
55 cmd := &cobra.Command{
56 Use: "list [<owner>]",
57 Args: cobra.MaximumNArgs(1),
58 Short: "List repositories owned by user or organization",
59 Long: heredoc.Docf(`
60 List repositories owned by a user or organization.
61
62 Note that the list will only include repositories owned by the provided argument,
63 and the %[1]s--fork%[1]s or %[1]s--source%[1]s flags will not traverse ownership boundaries. For example,
64 when listing the forks in an organization, the output would not include those owned by individual users.
65 `, "`"),
66 Aliases: []string{"ls"},
67 RunE: func(c *cobra.Command, args []string) error {
68 if opts.Limit < 1 {
69 return cmdutil.FlagErrorf("invalid limit: %v", opts.Limit)
70 }
71
72 if err := cmdutil.MutuallyExclusive("specify only one of `--public`, `--private`, or `--visibility`", flagPublic, flagPrivate, opts.Visibility != ""); err != nil {
73 return err
74 }
75 if opts.Source && opts.Fork {
76 return cmdutil.FlagErrorf("specify only one of `--source` or `--fork`")
77 }
78 if opts.Archived && opts.NonArchived {
79 return cmdutil.FlagErrorf("specify only one of `--archived` or `--no-archived`")
80 }
81
82 if flagPrivate {
83 opts.Visibility = "private"
84 } else if flagPublic {
85 opts.Visibility = "public"
86 }
87
88 if len(args) > 0 {
89 opts.Owner = args[0]
90 }
91
92 if runF != nil {
93 return runF(&opts)
94 }
95 return listRun(&opts)
96 },
97 }
98
99 cmd.Flags().IntVarP(&opts.Limit, "limit", "L", 30, "Maximum number of repositories to list")

Callers 2

TestNewCmdListFunction · 0.70
runCommandFunction · 0.70

Calls 5

FlagErrorfFunction · 0.92
MutuallyExclusiveFunction · 0.92
StringEnumFlagFunction · 0.92
AddJSONFlagsFunction · 0.92
listRunFunction · 0.70

Tested by 2

TestNewCmdListFunction · 0.56
runCommandFunction · 0.56