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

Function NewCmdList

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

Source from the content-addressed store, hash-verified

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