Improve CLI logout flow (#1692)

* Improve CLI logout flow

* Fix lint error

* Make notLoggedInMessage a const

* successful logout with a msg when cfg files are absent

* use require, os.remove, show only one message, add prompt
This commit is contained in:
Abhineet Jain
2022-05-24 13:11:01 -04:00
committed by GitHub
parent 33e2e40942
commit 7ba6449054
4 changed files with 185 additions and 26 deletions
+10 -9
View File
@@ -31,13 +31,14 @@ var (
)
const (
varURL = "url"
varToken = "token"
varAgentToken = "agent-token"
varAgentURL = "agent-url"
varGlobalConfig = "global-config"
varNoOpen = "no-open"
varForceTty = "force-tty"
varURL = "url"
varToken = "token"
varAgentToken = "agent-token"
varAgentURL = "agent-url"
varGlobalConfig = "global-config"
varNoOpen = "no-open"
varForceTty = "force-tty"
notLoggedInMessage = "You are not logged in. Try logging in using 'coder login <url>'."
)
func init() {
@@ -117,7 +118,7 @@ func createClient(cmd *cobra.Command) (*codersdk.Client, error) {
if err != nil {
// If the configuration files are absent, the user is logged out
if os.IsNotExist(err) {
return nil, xerrors.New("You are not logged in. Try logging in using 'coder login <url>'.")
return nil, xerrors.New(notLoggedInMessage)
}
return nil, err
}
@@ -132,7 +133,7 @@ func createClient(cmd *cobra.Command) (*codersdk.Client, error) {
if err != nil {
// If the configuration files are absent, the user is logged out
if os.IsNotExist(err) {
return nil, xerrors.New("You are not logged in. Try logging in using 'coder login <url>'.")
return nil, xerrors.New(notLoggedInMessage)
}
return nil, err
}