From 2abe1b329442d82cbee74f088f1097b495126391 Mon Sep 17 00:00:00 2001 From: Jonathan Fenwick Date: Tue, 7 Jun 2022 16:26:53 +0100 Subject: [PATCH] Remove auth logout confirmation prompt (#5751) --- pkg/cmd/auth/logout/logout.go | 19 +-------------- pkg/cmd/auth/logout/logout_test.go | 37 ++++++++++++------------------ 2 files changed, 16 insertions(+), 40 deletions(-) diff --git a/pkg/cmd/auth/logout/logout.go b/pkg/cmd/auth/logout/logout.go index 60b1ce6ef..04cb2a087 100644 --- a/pkg/cmd/auth/logout/logout.go +++ b/pkg/cmd/auth/logout/logout.go @@ -19,8 +19,7 @@ type LogoutOptions struct { HttpClient func() (*http.Client, error) IO *iostreams.IOStreams Config func() (config.Config, error) - - Hostname string + Hostname string } func NewCmdLogout(f *cmdutil.Factory, runF func(*LogoutOptions) error) *cobra.Command { @@ -50,7 +49,6 @@ func NewCmdLogout(f *cmdutil.Factory, runF func(*LogoutOptions) error) *cobra.Co if opts.Hostname == "" && !opts.IO.CanPrompt() { return cmdutil.FlagErrorf("--hostname required when not running interactively") } - if runF != nil { return runF(opts) } @@ -135,21 +133,6 @@ func logoutRun(opts *LogoutOptions) error { usernameStr = fmt.Sprintf(" account '%s'", username) } - if opts.IO.CanPrompt() { - var keepGoing bool - err := prompt.SurveyAskOne(&survey.Confirm{ - Message: fmt.Sprintf("Are you sure you want to log out of %s%s?", hostname, usernameStr), - Default: true, - }, &keepGoing) - if err != nil { - return fmt.Errorf("could not prompt: %w", err) - } - - if !keepGoing { - return nil - } - } - cfg.UnsetHost(hostname) err = cfg.WriteHosts() if err != nil { diff --git a/pkg/cmd/auth/logout/logout_test.go b/pkg/cmd/auth/logout/logout_test.go index eaa13cde0..73fd50d40 100644 --- a/pkg/cmd/auth/logout/logout_test.go +++ b/pkg/cmd/auth/logout/logout_test.go @@ -24,12 +24,9 @@ func Test_NewCmdLogout(t *testing.T) { tty bool }{ { - name: "tty with hostname", - tty: true, - cli: "--hostname harry.mason", - wants: LogoutOptions{ - Hostname: "harry.mason", - }, + name: "nontty no arguments", + cli: "", + wantsErr: true, }, { name: "tty no arguments", @@ -40,16 +37,19 @@ func Test_NewCmdLogout(t *testing.T) { }, }, { - name: "nontty with hostname", + name: "tty with hostname", + tty: true, cli: "--hostname harry.mason", wants: LogoutOptions{ Hostname: "harry.mason", }, }, { - name: "nontty no arguments", - cli: "", - wantsErr: true, + name: "nontty with hostname", + cli: "--hostname harry.mason", + wants: LogoutOptions{ + Hostname: "harry.mason", + }, }, } for _, tt := range tests { @@ -107,17 +107,13 @@ func Test_logoutRun_tty(t *testing.T) { wantHosts: "cheryl.mason:\n oauth_token: abc123\n", askStubs: func(as *prompt.AskStubber) { as.StubPrompt("What account do you want to log out of?").AnswerWith("github.com") - as.StubPrompt("Are you sure you want to log out of github.com account 'cybilb'?").AnswerWith(true) }, wantErrOut: regexp.MustCompile(`Logged out of github.com account 'cybilb'`), }, { - name: "no arguments, one host", - opts: &LogoutOptions{}, - cfgHosts: []string{"github.com"}, - askStubs: func(as *prompt.AskStubber) { - as.StubPrompt("Are you sure you want to log out of github.com account 'cybilb'?").AnswerWith(true) - }, + name: "no arguments, one host", + opts: &LogoutOptions{}, + cfgHosts: []string{"github.com"}, wantErrOut: regexp.MustCompile(`Logged out of github.com account 'cybilb'`), }, { @@ -130,11 +126,8 @@ func Test_logoutRun_tty(t *testing.T) { opts: &LogoutOptions{ Hostname: "cheryl.mason", }, - cfgHosts: []string{"cheryl.mason", "github.com"}, - wantHosts: "github.com:\n oauth_token: abc123\n", - askStubs: func(as *prompt.AskStubber) { - as.StubPrompt("Are you sure you want to log out of cheryl.mason account 'cybilb'?").AnswerWith(true) - }, + cfgHosts: []string{"cheryl.mason", "github.com"}, + wantHosts: "github.com:\n oauth_token: abc123\n", wantErrOut: regexp.MustCompile(`Logged out of cheryl.mason account 'cybilb'`), }, }