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

Function NewCmdList

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

Source from the content-addressed store, hash-verified

47const fieldNumSelectedRepos = "numSelectedRepos"
48
49func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command {
50 opts := &ListOptions{
51 IO: f.IOStreams,
52 Config: f.Config,
53 HttpClient: f.HttpClient,
54 Now: time.Now,
55 Prompter: f.Prompter,
56 }
57
58 cmd := &cobra.Command{
59 Use: "list",
60 Short: "List secrets",
61 Long: heredoc.Doc(`
62 List secrets on one of the following levels:
63 - repository (default): available to GitHub Actions runs, Agents sessions, or Dependabot in a repository
64 - environment: available to GitHub Actions runs for a deployment environment in a repository
65 - organization: available to GitHub Actions runs, Agents sessions, Dependabot, or Codespaces within an organization
66 - user: available to Codespaces for your user
67 `),
68 Aliases: []string{"ls"},
69 Args: cobra.NoArgs,
70 RunE: func(cmd *cobra.Command, args []string) error {
71 // If the user specified a repo directly, then we're using the OverrideBaseRepoFunc set by EnableRepoOverride
72 // So there's no reason to use the specialised BaseRepoFunc that requires remote disambiguation.
73 opts.BaseRepo = f.BaseRepo
74 isRepoUserProvided := cmd.Flags().Changed("repo") || os.Getenv("GH_REPO") != ""
75 if !isRepoUserProvided {
76 // If they haven't specified a repo directly, then we will wrap the BaseRepoFunc in one that errors if
77 // there might be multiple valid remotes.
78 opts.BaseRepo = shared.RequireNoAmbiguityBaseRepoFunc(opts.BaseRepo, f.Remotes)
79 // But if we are able to prompt, then we will wrap that up in a BaseRepoFunc that can prompt the user to
80 // resolve the ambiguity.
81 if opts.IO.CanPrompt() {
82 opts.BaseRepo = shared.PromptWhenAmbiguousBaseRepoFunc(opts.BaseRepo, f.IOStreams, f.Prompter)
83 }
84 }
85
86 if err := cmdutil.MutuallyExclusive("specify only one of `--org`, `--env`, or `--user`", opts.OrgName != "", opts.EnvName != "", opts.UserSecrets); err != nil {
87 return err
88 }
89
90 if runF != nil {
91 return runF(opts)
92 }
93
94 return listRun(opts)
95 },
96 }
97
98 cmd.Flags().StringVarP(&opts.OrgName, "org", "o", "", "List secrets for an organization")
99 cmd.Flags().StringVarP(&opts.EnvName, "env", "e", "", "List secrets for an environment")
100 cmd.Flags().BoolVarP(&opts.UserSecrets, "user", "u", false, "List a secret for your user")
101 cmdutil.StringEnumFlag(cmd, &opts.Application, "app", "a", "", []string{shared.Actions, shared.Agents, shared.Codespaces, shared.Dependabot}, "List secrets for a specific application")
102 cmdutil.AddJSONFlags(cmd, &opts.Exporter, secretFields)
103 return cmd
104}
105
106func listRun(opts *ListOptions) error {

Callers 2

Test_NewCmdListFunction · 0.70

Calls 7

MutuallyExclusiveFunction · 0.92
StringEnumFlagFunction · 0.92
AddJSONFlagsFunction · 0.92
CanPromptMethod · 0.80
listRunFunction · 0.70

Tested by 2

Test_NewCmdListFunction · 0.56