Handle logout having no candidates
This commit is contained in:
parent
df274d4f3a
commit
7667fbdb5a
2 changed files with 14 additions and 1 deletions
|
|
@ -110,7 +110,9 @@ func logoutRun(opts *LogoutOptions) error {
|
|||
}
|
||||
}
|
||||
|
||||
if len(candidates) == 1 {
|
||||
if len(candidates) == 0 {
|
||||
return errors.New("no user accounts matched that criteria")
|
||||
} else if len(candidates) == 1 {
|
||||
hostname = candidates[0].host
|
||||
username = candidates[0].user
|
||||
} else if !opts.IO.CanPrompt() {
|
||||
|
|
|
|||
|
|
@ -240,6 +240,17 @@ func Test_logoutRun_tty(t *testing.T) {
|
|||
},
|
||||
wantErr: "not logged in as unknown-user on ghe.io",
|
||||
},
|
||||
{
|
||||
name: "errors when user is specified but doesn't exist on any host",
|
||||
opts: &LogoutOptions{
|
||||
Username: "unknown-user",
|
||||
},
|
||||
cfgHosts: []hostUsers{
|
||||
{"github.com", []user{"monalisa"}},
|
||||
{"ghe.io", []user{"monalisa"}},
|
||||
},
|
||||
wantErr: "no user accounts matched that criteria",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue