diff --git a/pkg/cmd/auth/logout/logout.go b/pkg/cmd/auth/logout/logout.go index 5077cdae1..a400dfc93 100644 --- a/pkg/cmd/auth/logout/logout.go +++ b/pkg/cmd/auth/logout/logout.go @@ -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() { diff --git a/pkg/cmd/auth/logout/logout_test.go b/pkg/cmd/auth/logout/logout_test.go index 57f40a59c..d3bfa6ca2 100644 --- a/pkg/cmd/auth/logout/logout_test.go +++ b/pkg/cmd/auth/logout/logout_test.go @@ -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 {