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

Function NewCmdList

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

Source from the content-addressed store, hash-verified

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