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

Function NewCmdDelete

pkg/cmd/secret/delete/delete.go:32–88  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*DeleteOptions) error)

Source from the content-addressed store, hash-verified

30}
31
32func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Command {
33 opts := &DeleteOptions{
34 IO: f.IOStreams,
35 Config: f.Config,
36 HttpClient: f.HttpClient,
37 }
38
39 cmd := &cobra.Command{
40 Use: "delete <secret-name>",
41 Short: "Delete secrets",
42 Long: heredoc.Doc(`
43 Delete a secret on one of the following levels:
44 - repository (default): available to GitHub Actions runs, Agents sessions, or Dependabot in a repository
45 - environment: available to GitHub Actions runs for a deployment environment in a repository
46 - organization: available to GitHub Actions runs, Agents sessions, Dependabot, or Codespaces within an organization
47 - user: available to Codespaces for your user
48 `),
49 Args: cobra.ExactArgs(1),
50 RunE: func(cmd *cobra.Command, args []string) error {
51 // If the user specified a repo directly, then we're using the OverrideBaseRepoFunc set by EnableRepoOverride
52 // So there's no reason to use the specialised BaseRepoFunc that requires remote disambiguation.
53 opts.BaseRepo = f.BaseRepo
54 isRepoUserProvided := cmd.Flags().Changed("repo") || os.Getenv("GH_REPO") != ""
55 if !isRepoUserProvided {
56 // If they haven't specified a repo directly, then we will wrap the BaseRepoFunc in one that errors if
57 // there might be multiple valid remotes.
58 opts.BaseRepo = shared.RequireNoAmbiguityBaseRepoFunc(opts.BaseRepo, f.Remotes)
59 // But if we are able to prompt, then we will wrap that up in a BaseRepoFunc that can prompt the user to
60 // resolve the ambiguity.
61 if opts.IO.CanPrompt() {
62 opts.BaseRepo = shared.PromptWhenAmbiguousBaseRepoFunc(opts.BaseRepo, f.IOStreams, f.Prompter)
63 }
64 }
65
66 if err := cmdutil.MutuallyExclusive("specify only one of `--org`, `--env`, or `--user`", opts.OrgName != "", opts.EnvName != "", opts.UserSecrets); err != nil {
67 return err
68 }
69
70 opts.SecretName = args[0]
71
72 if runF != nil {
73 return runF(opts)
74 }
75
76 return removeRun(opts)
77 },
78 Aliases: []string{
79 "remove",
80 },
81 }
82 cmd.Flags().StringVarP(&opts.OrgName, "org", "o", "", "Delete a secret for an organization")
83 cmd.Flags().StringVarP(&opts.EnvName, "env", "e", "", "Delete a secret for an environment")
84 cmd.Flags().BoolVarP(&opts.UserSecrets, "user", "u", false, "Delete a secret for your user")
85 cmdutil.StringEnumFlag(cmd, &opts.Application, "app", "a", "", []string{shared.Actions, shared.Agents, shared.Codespaces, shared.Dependabot}, "Delete a secret for a specific application")
86
87 return cmd
88}
89

Callers 2

TestNewCmdDeleteFunction · 0.70

Calls 6

MutuallyExclusiveFunction · 0.92
StringEnumFlagFunction · 0.92
CanPromptMethod · 0.80
removeRunFunction · 0.70

Tested by 2

TestNewCmdDeleteFunction · 0.56