Skip to content

Commit 0584479

Browse files
committed
Make notLoggedInMessage a const
1 parent a7775b0 commit 0584479

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

cli/logout.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,25 @@ func logout() *cobra.Command {
1515
RunE: func(cmd *cobra.Command, args []string) error {
1616
config := createConfig(cmd)
1717

18-
loginHelper := "You are not logged in. Try logging in using 'coder login <url>'."
19-
2018
err := config.URL().Delete()
21-
2219
if err != nil {
2320
// If the URL configuration file is absent, the user is logged out
2421
if os.IsNotExist(err) {
25-
return xerrors.New(loginHelper)
22+
return xerrors.New(notLoggedInMessage)
2623
}
2724
return xerrors.Errorf("remove URL file: %w", err)
2825
}
2926

3027
err = config.Session().Delete()
31-
3228
if err != nil {
3329
// If the session configuration file is absent, the user is logged out
3430
if os.IsNotExist(err) {
35-
return xerrors.New(loginHelper)
31+
return xerrors.New(notLoggedInMessage)
3632
}
3733
return xerrors.Errorf("remove session file: %w", err)
3834
}
3935

4036
err = config.Organization().Delete()
41-
4237
// If the organization configuration file is absent, we should still log out
4338
if err != nil && !os.IsNotExist(err) {
4439
return xerrors.Errorf("remove organization file: %w", err)

cli/root.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ var (
3131
)
3232

3333
const (
34-
varURL = "url"
35-
varToken = "token"
36-
varAgentToken = "agent-token"
37-
varAgentURL = "agent-url"
38-
varGlobalConfig = "global-config"
39-
varNoOpen = "no-open"
40-
varForceTty = "force-tty"
34+
varURL = "url"
35+
varToken = "token"
36+
varAgentToken = "agent-token"
37+
varAgentURL = "agent-url"
38+
varGlobalConfig = "global-config"
39+
varNoOpen = "no-open"
40+
varForceTty = "force-tty"
41+
notLoggedInMessage = "You are not logged in. Try logging in using 'coder login <url>'."
4142
)
4243

4344
func init() {
@@ -112,13 +113,12 @@ func Root() *cobra.Command {
112113
func createClient(cmd *cobra.Command) (*codersdk.Client, error) {
113114
root := createConfig(cmd)
114115
rawURL, err := cmd.Flags().GetString(varURL)
115-
loginHelper := "You are not logged in. Try logging in using 'coder login <url>'."
116116
if err != nil || rawURL == "" {
117117
rawURL, err = root.URL().Read()
118118
if err != nil {
119119
// If the configuration files are absent, the user is logged out
120120
if os.IsNotExist(err) {
121-
return nil, xerrors.New(loginHelper)
121+
return nil, xerrors.New(notLoggedInMessage)
122122
}
123123
return nil, err
124124
}
@@ -133,7 +133,7 @@ func createClient(cmd *cobra.Command) (*codersdk.Client, error) {
133133
if err != nil {
134134
// If the configuration files are absent, the user is logged out
135135
if os.IsNotExist(err) {
136-
return nil, xerrors.New(loginHelper)
136+
return nil, xerrors.New(notLoggedInMessage)
137137
}
138138
return nil, err
139139
}

0 commit comments

Comments
 (0)