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

Function NewCmdList

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

Source from the content-addressed store, hash-verified

34const fieldNumSelectedRepos = "numSelectedRepos"
35
36func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command {
37 opts := &ListOptions{
38 IO: f.IOStreams,
39 Config: f.Config,
40 HttpClient: f.HttpClient,
41 Now: time.Now,
42 }
43
44 cmd := &cobra.Command{
45 Use: "list",
46 Short: "List variables",
47 Long: heredoc.Doc(`
48 List variables on one of the following levels:
49 - repository (default): available to GitHub Actions runs or Dependabot in a repository
50 - environment: available to GitHub Actions runs for a deployment environment in a repository
51 - organization: available to GitHub Actions runs or Dependabot within an organization
52 `),
53 Aliases: []string{"ls"},
54 Args: cobra.NoArgs,
55 RunE: func(cmd *cobra.Command, args []string) error {
56 // support `-R, --repo` override
57 opts.BaseRepo = f.BaseRepo
58
59 if err := cmdutil.MutuallyExclusive("specify only one of `--org` or `--env`", opts.OrgName != "", opts.EnvName != ""); err != nil {
60 return err
61 }
62
63 if runF != nil {
64 return runF(opts)
65 }
66
67 return listRun(opts)
68 },
69 }
70
71 cmd.Flags().StringVarP(&opts.OrgName, "org", "o", "", "List variables for an organization")
72 cmd.Flags().StringVarP(&opts.EnvName, "env", "e", "", "List variables for an environment")
73 cmdutil.AddJSONFlags(cmd, &opts.Exporter, shared.VariableJSONFields)
74
75 return cmd
76}
77
78func listRun(opts *ListOptions) error {
79 client, err := opts.HttpClient()

Callers 1

TestNewCmdListFunction · 0.70

Calls 3

MutuallyExclusiveFunction · 0.92
AddJSONFlagsFunction · 0.92
listRunFunction · 0.70

Tested by 1

TestNewCmdListFunction · 0.56