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

Function NewCmdList

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

Source from the content-addressed store, hash-verified

32}
33
34func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command {
35 opts := ListOptions{
36 IO: f.IOStreams,
37 HttpClient: f.HttpClient,
38 }
39
40 cmd := &cobra.Command{
41 Use: "list",
42 Short: "List GitHub Actions caches",
43 Example: heredoc.Doc(`
44 # List caches for current repository
45 $ gh cache list
46
47 # List caches for specific repository
48 $ gh cache list --repo cli/cli
49
50 # List caches sorted by least recently accessed
51 $ gh cache list --sort last_accessed_at --order asc
52
53 # List caches that have keys matching a prefix (or that match exactly)
54 $ gh cache list --key key-prefix
55
56 # List caches for a specific branch, replace <branch-name> with the actual branch name
57 $ gh cache list --ref refs/heads/<branch-name>
58
59 # List caches for a specific pull request, replace <pr-number> with the actual pull request number
60 $ gh cache list --ref refs/pull/<pr-number>/merge
61 `),
62 Aliases: []string{"ls"},
63 Args: cobra.NoArgs,
64 RunE: func(cmd *cobra.Command, args []string) error {
65 // support `-R, --repo` override
66 opts.BaseRepo = f.BaseRepo
67
68 if opts.Limit < 1 {
69 return cmdutil.FlagErrorf("invalid limit: %v", opts.Limit)
70 }
71
72 if runF != nil {
73 return runF(&opts)
74 }
75
76 return listRun(&opts)
77 },
78 }
79
80 cmd.Flags().IntVarP(&opts.Limit, "limit", "L", 30, "Maximum number of caches to fetch")
81 cmdutil.StringEnumFlag(cmd, &opts.Order, "order", "O", "desc", []string{"asc", "desc"}, "Order of caches returned")
82 cmdutil.StringEnumFlag(cmd, &opts.Sort, "sort", "S", "last_accessed_at", []string{"created_at", "last_accessed_at", "size_in_bytes"}, "Sort fetched caches")
83 cmd.Flags().StringVarP(&opts.Key, "key", "k", "", "Filter by cache key prefix")
84 cmd.Flags().StringVarP(&opts.Ref, "ref", "r", "", "Filter by ref, formatted as refs/heads/<branch name> or refs/pull/<number>/merge")
85 cmdutil.AddJSONFlags(cmd, &opts.Exporter, shared.CacheFields)
86
87 return cmd
88}
89
90func listRun(opts *ListOptions) error {
91 repo, err := opts.BaseRepo()

Callers 1

TestNewCmdListFunction · 0.70

Calls 4

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

Tested by 1

TestNewCmdListFunction · 0.56