Change gh repo set-default --view to print to stderr when no default exists (#9431)

Change logging of `gh repo set-default --view` to `stderr` when no default exists to better conform with expectations and unix standards.

---------

Signed-off-by: Prabhat <iprabhatdev@gmail.com>
This commit is contained in:
Prabhat Kumar Sahu 2024-08-09 02:14:52 +05:30 committed by GitHub
parent 40ccd2ef92
commit ab34d868aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 6 deletions

View file

@ -121,12 +121,11 @@ func setDefaultRun(opts *SetDefaultOptions) error {
if opts.ViewMode {
if currentDefaultRepo != nil {
fmt.Fprintln(opts.IO.Out, displayRemoteRepoName(currentDefaultRepo))
} else if opts.IO.IsStdoutTTY() {
fmt.Fprintln(opts.IO.Out, "no default repository has been set; use `gh repo set-default` to select one")
} else {
fmt.Fprintln(opts.IO.ErrOut, "no default repository has been set; use `gh repo set-default` to select one")
}
return nil
}
cs := opts.IO.ColorScheme()
if opts.UnsetMode {

View file

@ -135,6 +135,7 @@ func TestDefaultRun(t *testing.T) {
gitStubs func(*run.CommandStubber)
prompterStubs func(*prompter.PrompterMock)
wantStdout string
wantStderr string
wantErr bool
errMsg string
}{
@ -175,10 +176,11 @@ func TestDefaultRun(t *testing.T) {
Repo: repo1,
},
},
wantStdout: "no default repository has been set; use `gh repo set-default` to select one\n",
wantStderr: "no default repository has been set; use `gh repo set-default` to select one\n",
},
{
name: "view mode no current default",
tty: false,
opts: SetDefaultOptions{ViewMode: true},
remotes: []*context.Remote{
{
@ -186,6 +188,7 @@ func TestDefaultRun(t *testing.T) {
Repo: repo1,
},
},
wantStderr: "no default repository has been set; use `gh repo set-default` to select one\n",
},
{
name: "view mode with base resolved current default",
@ -466,7 +469,7 @@ func TestDefaultRun(t *testing.T) {
return &http.Client{Transport: reg}, nil
}
io, _, stdout, _ := iostreams.Test()
io, _, stdout, stderr := iostreams.Test()
io.SetStdinTTY(tt.tty)
io.SetStdoutTTY(tt.tty)
io.SetStderrTTY(tt.tty)
@ -498,7 +501,11 @@ func TestDefaultRun(t *testing.T) {
return
}
assert.NoError(t, err)
assert.Equal(t, tt.wantStdout, stdout.String())
if tt.wantStdout != "" {
assert.Equal(t, tt.wantStdout, stdout.String())
} else {
assert.Equal(t, tt.wantStderr, stderr.String())
}
})
}
}