Handle logout having no candidates

This commit is contained in:
William Martin 2023-11-29 17:06:37 +01:00
parent df274d4f3a
commit 7667fbdb5a
2 changed files with 14 additions and 1 deletions

View file

@ -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() {

View file

@ -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 {