Skip to content

Commit 119085c

Browse files
authored
Merge pull request cli#12039 from Shion1305/shion/feat-12033
💡 (gh repo delete) Add warning when `--yes` is ignored without a repository, Closes: cli#12033
2 parents 489f96c + a7f1457 commit 119085c

2 files changed

Lines changed: 38 additions & 30 deletions

File tree

pkg/cmd/repo/delete/delete.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Co
6262
if !opts.IO.CanPrompt() {
6363
return cmdutil.FlagErrorf("cannot non-interactively delete current repository. Please specify a repository or run interactively")
6464
}
65+
_, _ = fmt.Fprintln(opts.IO.ErrOut, "Warning: `--yes` is ignored since no repository was specified")
6566
opts.Confirmed = false
6667
}
6768

pkg/cmd/repo/delete/delete_test.go

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ import (
1616

1717
func TestNewCmdDelete(t *testing.T) {
1818
tests := []struct {
19-
name string
20-
input string
21-
tty bool
22-
output DeleteOptions
23-
wantErr bool
24-
errMsg string
19+
name string
20+
input string
21+
tty bool
22+
output DeleteOptions
23+
wantErr bool
24+
wantErrMsg string
25+
wantStderr string
2526
}{
2627
{
2728
name: "confirm flag",
@@ -36,11 +37,11 @@ func TestNewCmdDelete(t *testing.T) {
3637
output: DeleteOptions{RepoArg: "OWNER/REPO", Confirmed: true},
3738
},
3839
{
39-
name: "no confirmation notty",
40-
input: "OWNER/REPO",
41-
output: DeleteOptions{RepoArg: "OWNER/REPO"},
42-
wantErr: true,
43-
errMsg: "--yes required when not running interactively",
40+
name: "no confirmation notty",
41+
input: "OWNER/REPO",
42+
output: DeleteOptions{RepoArg: "OWNER/REPO"},
43+
wantErr: true,
44+
wantErrMsg: "--yes required when not running interactively",
4445
},
4546
{
4647
name: "base repo resolution",
@@ -49,33 +50,37 @@ func TestNewCmdDelete(t *testing.T) {
4950
output: DeleteOptions{},
5051
},
5152
{
52-
name: "yes flag ignored when no argument tty",
53-
tty: true,
54-
input: "--yes",
55-
output: DeleteOptions{Confirmed: false}, // --yes should be ignored
53+
name: "yes flag ignored when no argument tty",
54+
tty: true,
55+
input: "--yes",
56+
output: DeleteOptions{Confirmed: false}, // --yes should be ignored
57+
wantErr: false,
58+
wantStderr: "Warning: `--yes` is ignored since no repository was specified\n",
5659
},
5760
{
58-
name: "yes flag error when no argument notty",
59-
input: "--yes",
60-
wantErr: true,
61-
errMsg: "cannot non-interactively delete current repository. Please specify a repository or run interactively",
61+
name: "yes flag error when no argument notty",
62+
input: "--yes",
63+
wantErr: true,
64+
wantErrMsg: "cannot non-interactively delete current repository. Please specify a repository or run interactively",
6265
},
6366
{
64-
name: "confirm flag error when no argument notty",
65-
input: "--confirm",
66-
wantErr: true,
67-
errMsg: "cannot non-interactively delete current repository. Please specify a repository or run interactively",
67+
name: "confirm flag error when no argument notty",
68+
input: "--confirm",
69+
wantErr: true,
70+
wantErrMsg: "cannot non-interactively delete current repository. Please specify a repository or run interactively",
6871
},
6972
{
70-
name: "confirm flag also ignored when no argument tty",
71-
tty: true,
72-
input: "--confirm",
73-
output: DeleteOptions{Confirmed: false}, // --confirm should also be ignored
73+
name: "confirm flag also ignored when no argument tty",
74+
tty: true,
75+
input: "--confirm",
76+
output: DeleteOptions{Confirmed: false}, // --confirm should also be ignored
77+
wantStderr: "Warning: `--yes` is ignored since no repository was specified\n",
78+
// Note: This does not confuse the user, as deprecation warnings are shown: "Flag --confirm has been deprecated, use `--yes` instead"
7479
},
7580
}
7681
for _, tt := range tests {
7782
t.Run(tt.name, func(t *testing.T) {
78-
ios, _, _, _ := iostreams.Test()
83+
ios, _, _, stdErr := iostreams.Test()
7984
ios.SetStdinTTY(tt.tty)
8085
ios.SetStdoutTTY(tt.tty)
8186
f := &cmdutil.Factory{
@@ -91,15 +96,17 @@ func TestNewCmdDelete(t *testing.T) {
9196
cmd.SetArgs(argv)
9297
cmd.SetIn(&bytes.Buffer{})
9398
cmd.SetOut(&bytes.Buffer{})
94-
cmd.SetErr(&bytes.Buffer{})
99+
cmd.SetErr(stdErr)
95100

96101
_, err = cmd.ExecuteC()
102+
97103
if tt.wantErr {
98104
assert.Error(t, err)
99-
assert.Equal(t, tt.errMsg, err.Error())
105+
assert.Equal(t, tt.wantErrMsg, err.Error())
100106
return
101107
}
102108
assert.NoError(t, err)
109+
assert.Equal(t, tt.wantStderr, stdErr.String())
103110
assert.Equal(t, tt.output.RepoArg, gotOpts.RepoArg)
104111
})
105112
}

0 commit comments

Comments
 (0)