Skip to content

Commit bcd48c6

Browse files
authored
Merge pull request #434 from depot/luke/jj-ksnuwkqpkkvq
feat: `vars rm` alias; accept list of secrets and vars to remove
2 parents 56245e3 + b010f41 commit bcd48c6

File tree

2 files changed

+38
-30
lines changed

2 files changed

+38
-30
lines changed

pkg/cmd/ci/secrets.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -195,23 +195,21 @@ func NewCmdSecretsRemove() *cobra.Command {
195195
)
196196

197197
cmd := &cobra.Command{
198-
Use: "remove SECRET_NAME",
199-
Short: "Remove a CI secret",
200-
Long: `Remove a CI secret from your organization.`,
198+
Use: "remove SECRET_NAME [SECRET_NAME...]",
199+
Short: "Remove one or more CI secrets",
200+
Long: `Remove one or more CI secrets from your organization.`,
201201
Example: ` # Remove a secret
202202
depot ci secrets remove GITHUB_TOKEN
203203
204-
# Remove a secret without confirmation prompt
205-
depot ci secrets remove MY_API_KEY --force`,
204+
# Remove multiple secrets
205+
depot ci secrets remove GITHUB_TOKEN MY_API_KEY DATABASE_URL
206+
207+
# Remove secrets without confirmation prompt
208+
depot ci secrets remove GITHUB_TOKEN MY_API_KEY --force`,
206209
Aliases: []string{"rm"},
207-
Args: cobra.ExactArgs(1),
210+
Args: cobra.MinimumNArgs(1),
208211
RunE: func(cmd *cobra.Command, args []string) error {
209212
ctx := cmd.Context()
210-
secretName := args[0]
211-
212-
if secretName == "" {
213-
return fmt.Errorf("secret name cannot be empty")
214-
}
215213

216214
if orgID == "" {
217215
orgID = config.GetCurrentOrganization()
@@ -226,7 +224,8 @@ func NewCmdSecretsRemove() *cobra.Command {
226224
}
227225

228226
if !force {
229-
prompt := fmt.Sprintf("Are you sure you want to remove CI secret '%s'? (y/N): ", secretName)
227+
names := strings.Join(args, ", ")
228+
prompt := fmt.Sprintf("Are you sure you want to remove CI secret(s) %s? (y/N): ", names)
230229
y, err := helpers.PromptForYN(prompt)
231230
if err != nil {
232231
return fmt.Errorf("failed to read confirmation: %w", err)
@@ -235,12 +234,14 @@ func NewCmdSecretsRemove() *cobra.Command {
235234
}
236235
}
237236

238-
err = api.CIDeleteSecret(ctx, tokenVal, orgID, secretName)
239-
if err != nil {
240-
return fmt.Errorf("failed to remove secret: %w", err)
237+
for _, secretName := range args {
238+
err := api.CIDeleteSecret(ctx, tokenVal, orgID, secretName)
239+
if err != nil {
240+
return fmt.Errorf("failed to remove secret '%s': %w", secretName, err)
241+
}
242+
fmt.Printf("Successfully removed CI secret '%s'\n", secretName)
241243
}
242244

243-
fmt.Printf("Successfully removed CI secret '%s'\n", secretName)
244245
return nil
245246
},
246247
}

pkg/cmd/ci/vars.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,21 @@ func NewCmdVarsRemove() *cobra.Command {
182182
)
183183

184184
cmd := &cobra.Command{
185-
Use: "remove VAR_NAME",
186-
Short: "Remove a CI variable",
187-
Long: "Remove a CI variable from your organization.",
188-
Args: cobra.ExactArgs(1),
185+
Use: "remove VAR_NAME [VAR_NAME...]",
186+
Short: "Remove one or more CI variables",
187+
Long: "Remove one or more CI variables from your organization.",
188+
Example: ` # Remove a variable
189+
depot ci vars remove GITHUB_REPO
190+
191+
# Remove multiple variables
192+
depot ci vars remove GITHUB_REPO MY_SERVICE_NAME DEPLOY_ENV
193+
194+
# Remove variables without confirmation prompt
195+
depot ci vars remove GITHUB_REPO MY_SERVICE_NAME --force`,
196+
Aliases: []string{"rm"},
197+
Args: cobra.MinimumNArgs(1),
189198
RunE: func(cmd *cobra.Command, args []string) error {
190199
ctx := cmd.Context()
191-
varName := args[0]
192-
193-
if varName == "" {
194-
return fmt.Errorf("variable name cannot be empty")
195-
}
196200

197201
if orgID == "" {
198202
orgID = config.GetCurrentOrganization()
@@ -207,7 +211,8 @@ func NewCmdVarsRemove() *cobra.Command {
207211
}
208212

209213
if !force {
210-
prompt := fmt.Sprintf("Are you sure you want to remove CI variable '%s'? (y/N): ", varName)
214+
names := strings.Join(args, ", ")
215+
prompt := fmt.Sprintf("Are you sure you want to remove CI variable(s) %s? (y/N): ", names)
211216
y, err := helpers.PromptForYN(prompt)
212217
if err != nil {
213218
return fmt.Errorf("failed to read confirmation: %w", err)
@@ -216,12 +221,14 @@ func NewCmdVarsRemove() *cobra.Command {
216221
}
217222
}
218223

219-
err = api.CIDeleteVariable(ctx, tokenVal, orgID, varName)
220-
if err != nil {
221-
return fmt.Errorf("failed to remove CI variable: %w", err)
224+
for _, varName := range args {
225+
err := api.CIDeleteVariable(ctx, tokenVal, orgID, varName)
226+
if err != nil {
227+
return fmt.Errorf("failed to remove CI variable '%s': %w", varName, err)
228+
}
229+
fmt.Printf("Successfully removed CI variable '%s'\n", varName)
222230
}
223231

224-
fmt.Printf("Successfully removed CI variable '%s'\n", varName)
225232
return nil
226233
},
227234
}

0 commit comments

Comments
 (0)