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

Function NewCmdList

pkg/cmd/issue/artifact/list/list.go:36–85  ·  view source on GitHub ↗

NewCmdList creates the gh issue artifact list command.

(f *cmdutil.Factory, runF func(*ListOptions) error)

Source from the content-addressed store, hash-verified

34
35// NewCmdList creates the gh issue artifact list command.
36func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command {
37 opts := &ListOptions{
38 IO: f.IOStreams,
39 Now: time.Now,
40 }
41
42 cmd := &cobra.Command{
43 Use: "list {<issue-number> | <issue-url>}",
44 Short: "List artifacts on an issue (preview)",
45 Long: heredoc.Docf(`
46 List the artifacts on an issue, in number order. Every artifact is listed
47 unless you set %[1]s--limit%[1]s.
48 `, "`"),
49 Example: heredoc.Doc(`
50 # List the artifacts on issue 142
51 $ gh issue artifact list 142
52
53 # List only links
54 $ gh issue artifact list 142 --type link
55
56 # Print artifact numbers and names as JSON
57 $ gh issue artifact list 142 --json number,name
58 `),
59 Aliases: []string{"ls"},
60 Args: cobra.ExactArgs(1),
61 RunE: func(cmd *cobra.Command, args []string) error {
62 if cmd.Flags().Changed("limit") && opts.Limit < 1 {
63 return cmdutil.FlagErrorf("invalid limit: %v", opts.Limit)
64 }
65
66 var err error
67 opts.IssueNumber, opts.BaseRepo, err = shared.ParseIssueArg(args[0], f.BaseRepo)
68 if err != nil {
69 return cmdutil.FlagErrorWrap(err)
70 }
71 opts.Client = shared.ClientFunc(f)
72
73 if runF != nil {
74 return runF(opts)
75 }
76 return listRun(opts)
77 },
78 }
79
80 cmd.Flags().IntVarP(&opts.Limit, "limit", "L", 0, "Maximum number of artifacts to fetch")
81 cmdutil.StringEnumFlag(cmd, &opts.Type, "type", "", "", []string{client.TypeGeneric, client.TypePlan, client.TypeLink, client.TypeEmbeddedHTML}, "Filter by type")
82 cmdutil.AddJSONFlags(cmd, &opts.Exporter, client.ArtifactFields)
83
84 return cmd
85}
86
87func listRun(opts *ListOptions) error {
88 repo, err := opts.BaseRepo()

Callers 1

TestNewCmdListFunction · 0.70

Calls 8

FlagErrorfFunction · 0.92
ParseIssueArgFunction · 0.92
FlagErrorWrapFunction · 0.92
ClientFuncFunction · 0.92
StringEnumFlagFunction · 0.92
AddJSONFlagsFunction · 0.92
ChangedMethod · 0.80
listRunFunction · 0.70

Tested by 1

TestNewCmdListFunction · 0.56