Allow gh repo set-default --view without repo argument (#7441)
This commit is contained in:
parent
07ed1e4e8a
commit
bd749b67f6
2 changed files with 16 additions and 5 deletions
|
|
@ -86,7 +86,7 @@ func NewCmdSetDefault(f *cmdutil.Factory, runF func(*SetDefaultOptions) error) *
|
|||
}
|
||||
}
|
||||
|
||||
if !opts.IO.CanPrompt() && opts.Repo == nil {
|
||||
if !opts.ViewMode && !opts.IO.CanPrompt() && opts.Repo == nil {
|
||||
return cmdutil.FlagErrorf("repository required when not running interactively")
|
||||
}
|
||||
|
||||
|
|
@ -119,10 +119,10 @@ func setDefaultRun(opts *SetDefaultOptions) error {
|
|||
currentDefaultRepo, _ := remotes.ResolvedRemote()
|
||||
|
||||
if opts.ViewMode {
|
||||
if currentDefaultRepo == nil {
|
||||
fmt.Fprintln(opts.IO.Out, "no default repository has been set; use `gh repo set-default` to select one")
|
||||
} else {
|
||||
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")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -166,7 +166,8 @@ func TestDefaultRun(t *testing.T) {
|
|||
wantStdout: "no default repository has been set\n",
|
||||
},
|
||||
{
|
||||
name: "view mode no current default",
|
||||
name: "tty view mode no current default",
|
||||
tty: true,
|
||||
opts: SetDefaultOptions{ViewMode: true},
|
||||
remotes: []*context.Remote{
|
||||
{
|
||||
|
|
@ -176,6 +177,16 @@ func TestDefaultRun(t *testing.T) {
|
|||
},
|
||||
wantStdout: "no default repository has been set; use `gh repo set-default` to select one\n",
|
||||
},
|
||||
{
|
||||
name: "view mode no current default",
|
||||
opts: SetDefaultOptions{ViewMode: true},
|
||||
remotes: []*context.Remote{
|
||||
{
|
||||
Remote: &git.Remote{Name: "origin"},
|
||||
Repo: repo1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "view mode with base resolved current default",
|
||||
opts: SetDefaultOptions{ViewMode: true},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue