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

Function newCmdList

pkg/cmd/label/list.go:28–82  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*listOptions) error)

Source from the content-addressed store, hash-verified

26}
27
28func newCmdList(f *cmdutil.Factory, runF func(*listOptions) error) *cobra.Command {
29 opts := listOptions{
30 Browser: f.Browser,
31 HttpClient: f.HttpClient,
32 IO: f.IOStreams,
33 }
34
35 cmd := &cobra.Command{
36 Use: "list",
37 Short: "List labels in a repository",
38 Long: heredoc.Docf(`
39 Display labels in a GitHub repository.
40
41 When using the %[1]s--search%[1]s flag results are sorted by best match of the query.
42 This behavior cannot be configured with the %[1]s--order%[1]s or %[1]s--sort%[1]s flags.
43 `, "`"),
44 Example: heredoc.Doc(`
45 # Sort labels by name
46 $ gh label list --sort name
47
48 # Find labels with "bug" in the name or description
49 $ gh label list --search bug
50 `),
51 Args: cobra.NoArgs,
52 Aliases: []string{"ls"},
53 RunE: func(c *cobra.Command, args []string) error {
54 // support `-R, --repo` override
55 opts.BaseRepo = f.BaseRepo
56
57 if opts.Query.Limit < 1 {
58 return cmdutil.FlagErrorf("invalid limit: %v", opts.Query.Limit)
59 }
60
61 if opts.Query.Query != "" &&
62 (c.Flags().Changed("order") || c.Flags().Changed("sort")) {
63 return cmdutil.FlagErrorf("cannot specify `--order` or `--sort` with `--search`")
64 }
65
66 if runF != nil {
67 return runF(&opts)
68 }
69 return listRun(&opts)
70 },
71 }
72
73 cmd.Flags().BoolVarP(&opts.WebMode, "web", "w", false, "List labels in the web browser")
74 cmd.Flags().IntVarP(&opts.Query.Limit, "limit", "L", 30, "Maximum number of labels to fetch")
75 cmd.Flags().StringVarP(&opts.Query.Query, "search", "S", "", "Search label names and descriptions")
76 cmdutil.StringEnumFlag(cmd, &opts.Query.Order, "order", "", defaultOrder, []string{"asc", "desc"}, "Order of labels returned")
77 cmdutil.StringEnumFlag(cmd, &opts.Query.Sort, "sort", "", defaultSort, []string{"created", "name"}, "Sort fetched labels")
78
79 cmdutil.AddJSONFlags(cmd, &opts.Exporter, labelFields)
80
81 return cmd
82}
83
84func listRun(opts *listOptions) error {
85 httpClient, err := opts.HttpClient()

Callers 2

NewCmdLabelFunction · 0.85
TestNewCmdListFunction · 0.85

Calls 4

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

Tested by 1

TestNewCmdListFunction · 0.68