Skip to content

Commit

Permalink
Rename --confirm flag to --yes for various destructive commands (c…
Browse files Browse the repository at this point in the history
  • Loading branch information
damiensedgwick authored Jan 26, 2023
1 parent f669a10 commit bab1b00
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 21 deletions.
6 changes: 4 additions & 2 deletions pkg/cmd/gpg-key/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Co
opts.KeyID = args[0]

if !opts.IO.CanPrompt() && !opts.Confirmed {
return cmdutil.FlagErrorf("--confirm required when not running interactively")
return cmdutil.FlagErrorf("--yes required when not running interactively")
}

if runF != nil {
Expand All @@ -48,7 +48,9 @@ func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Co
},
}

cmd.Flags().BoolVarP(&opts.Confirmed, "confirm", "y", false, "Skip the confirmation prompt")
cmd.Flags().BoolVar(&opts.Confirmed, "confirm", false, "Skip the confirmation prompt")
_ = cmd.Flags().MarkDeprecated("confirm", "use `--yes` instead")
cmd.Flags().BoolVarP(&opts.Confirmed, "yes", "y", false, "Skip the confirmation prompt")
return cmd
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/gpg-key/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestNewCmdDelete(t *testing.T) {
{
name: "confirm flag tty",
tty: true,
input: "ABC123 --confirm",
input: "ABC123 --yes",
output: DeleteOptions{KeyID: "ABC123", Confirmed: true},
},
{
Expand All @@ -45,11 +45,11 @@ func TestNewCmdDelete(t *testing.T) {
name: "no tty",
input: "ABC123",
wantErr: true,
wantErrMsg: "--confirm required when not running interactively",
wantErrMsg: "--yes required when not running interactively",
},
{
name: "confirm flag no tty",
input: "ABC123 --confirm",
input: "ABC123 --yes",
output: DeleteOptions{KeyID: "ABC123", Confirmed: true},
},
{
Expand Down
3 changes: 3 additions & 0 deletions pkg/cmd/issue/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Co
if runF != nil {
return runF(opts)
}

return deleteRun(opts)
},
}

cmd.Flags().BoolVar(&opts.Confirmed, "confirm", false, "confirm deletion without prompting")
_ = cmd.Flags().MarkDeprecated("confirm", "use `--yes` instead")
cmd.Flags().BoolVar(&opts.Confirmed, "yes", false, "confirm deletion without prompting")
return cmd
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/cmd/label/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func newCmdDelete(f *cmdutil.Factory, runF func(*deleteOptions) error) *cobra.Co
opts.Name = args[0]

if !opts.IO.CanPrompt() && !opts.Confirmed {
return cmdutil.FlagErrorf("--confirm required when not running interactively")
return cmdutil.FlagErrorf("--yes required when not running interactively")
}

if runF != nil {
Expand All @@ -53,6 +53,8 @@ func newCmdDelete(f *cmdutil.Factory, runF func(*deleteOptions) error) *cobra.Co
}

cmd.Flags().BoolVar(&opts.Confirmed, "confirm", false, "Confirm deletion without prompting")
_ = cmd.Flags().MarkDeprecated("confirm", "use `--yes` instead")
cmd.Flags().BoolVar(&opts.Confirmed, "yes", false, "Confirm deletion without prompting")

return cmd
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/label/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ func TestNewCmdDelete(t *testing.T) {
},
{
name: "confirm argument",
input: "test --confirm",
input: "test --yes",
output: deleteOptions{Name: "test", Confirmed: true},
},
{
name: "confirm no tty",
input: "test",
wantErr: true,
wantErrMsg: "--confirm required when not running interactively",
wantErrMsg: "--yes required when not running interactively",
},
}

Expand Down
8 changes: 6 additions & 2 deletions pkg/cmd/repo/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,20 @@ With no argument, archives the current repository.`),
}

if !opts.Confirmed && !opts.IO.CanPrompt() {
return cmdutil.FlagErrorf("--confirm required when not running interactively")
return cmdutil.FlagErrorf("--yes required when not running interactively")
}

if runF != nil {
return runF(opts)
}

return archiveRun(opts)
},
}

cmd.Flags().BoolVarP(&opts.Confirmed, "confirm", "y", false, "Skip the confirmation prompt")
cmd.Flags().BoolVar(&opts.Confirmed, "confirm", false, "Skip the confirmation prompt")
_ = cmd.Flags().MarkDeprecated("confirm", "use `--yes` instead")
cmd.Flags().BoolVarP(&opts.Confirmed, "yes", "y", false, "Skip the confirmation prompt")
return cmd
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/repo/archive/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestNewCmdArchive(t *testing.T) {
{
name: "no arguments no tty",
input: "",
errMsg: "--confirm required when not running interactively",
errMsg: "--yes required when not running interactively",
wantErr: true,
},
{
Expand Down
7 changes: 5 additions & 2 deletions pkg/cmd/repo/rename/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,23 @@ func NewCmdRename(f *cmdutil.Factory, runf func(*RenameOptions) error) *cobra.Co

if len(args) == 1 && !confirm && !opts.HasRepoOverride {
if !opts.IO.CanPrompt() {
return cmdutil.FlagErrorf("--confirm required when passing a single argument")
return cmdutil.FlagErrorf("--yes required when passing a single argument")
}
opts.DoConfirm = true
}

if runf != nil {
return runf(opts)
}

return renameRun(opts)
},
}

cmdutil.EnableRepoOverride(cmd, f)
cmd.Flags().BoolVarP(&confirm, "confirm", "y", false, "skip confirmation prompt")
cmd.Flags().BoolVar(&confirm, "confirm", false, "Skip confirmation prompt")
_ = cmd.Flags().MarkDeprecated("confirm", "use `--yes` instead")
cmd.Flags().BoolVarP(&confirm, "yes", "y", false, "Skip the confirmation prompt")

return cmd
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/repo/rename/rename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ func TestNewCmdRename(t *testing.T) {
},
{
name: "one argument no tty confirmed",
input: "REPO --confirm",
input: "REPO --yes",
output: RenameOptions{
newRepoSelector: "REPO",
},
},
{
name: "one argument no tty",
input: "REPO",
errMsg: "--confirm required when passing a single argument",
errMsg: "--yes required when passing a single argument",
wantErr: true,
},
{
name: "one argument tty confirmed",
input: "REPO --confirm",
input: "REPO --yes",
tty: true,
output: RenameOptions{
newRepoSelector: "REPO",
Expand Down
8 changes: 6 additions & 2 deletions pkg/cmd/ssh-key/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,21 @@ func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Co
opts.KeyID = args[0]

if !opts.IO.CanPrompt() && !opts.Confirmed {
return cmdutil.FlagErrorf("--confirm required when not running interactively")
return cmdutil.FlagErrorf("--yes required when not running interactively")
}

if runF != nil {
return runF(opts)
}

return deleteRun(opts)
},
}

cmd.Flags().BoolVarP(&opts.Confirmed, "confirm", "y", false, "Skip the confirmation prompt")
cmd.Flags().BoolVar(&opts.Confirmed, "confirm", false, "Skip the confirmation prompt")
_ = cmd.Flags().MarkDeprecated("confirm", "use `--yes` instead")
cmd.Flags().BoolVarP(&opts.Confirmed, "yes", "y", false, "Skip the confirmation prompt")

return cmd
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/ssh-key/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestNewCmdDelete(t *testing.T) {
{
name: "confirm flag tty",
tty: true,
input: "123 --confirm",
input: "123 --yes",
output: DeleteOptions{KeyID: "123", Confirmed: true},
},
{
Expand All @@ -45,11 +45,11 @@ func TestNewCmdDelete(t *testing.T) {
name: "no tty",
input: "123",
wantErr: true,
wantErrMsg: "--confirm required when not running interactively",
wantErrMsg: "--yes required when not running interactively",
},
{
name: "confirm flag no tty",
input: "123 --confirm",
input: "123 --yes",
output: DeleteOptions{KeyID: "123", Confirmed: true},
},
{
Expand Down

0 comments on commit bab1b00

Please sign in to comment.