1
1
package cli
2
2
3
3
import (
4
+ "context"
4
5
"flag"
5
6
"fmt"
6
7
"net/url"
@@ -110,10 +111,17 @@ func Root(subcommands []*cobra.Command) *cobra.Command {
110
111
return
111
112
}
112
113
113
- // Login handles checking the versions itself since it
114
- // has a handle to an unauthenticated client.
115
- // Server is skipped for obvious reasons.
116
- if cmd .Name () == "login" || cmd .Name () == "server" || cmd .Name () == "gitssh" {
114
+ // login handles checking the versions itself since it has a handle
115
+ // to an unauthenticated client.
116
+ //
117
+ // server is skipped for obvious reasons.
118
+ //
119
+ // agent is skipped because these checks use the global coder config
120
+ // and not the agent URL and token from the environment.
121
+ //
122
+ // gitssh is skipped because it's usually not called by users
123
+ // directly.
124
+ if cmd .Name () == "login" || cmd .Name () == "server" || cmd .Name () == "agent" || cmd .Name () == "gitssh" {
117
125
return
118
126
}
119
127
@@ -123,6 +131,7 @@ func Root(subcommands []*cobra.Command) *cobra.Command {
123
131
if err != nil {
124
132
return
125
133
}
134
+
126
135
err = checkVersions (cmd , client )
127
136
if err != nil {
128
137
// Just log the error here. We never want to fail a command
@@ -131,7 +140,14 @@ func Root(subcommands []*cobra.Command) *cobra.Command {
131
140
cliui .Styles .Warn .Render ("check versions error: %s" ), err )
132
141
_ , _ = fmt .Fprintln (cmd .ErrOrStderr ())
133
142
}
134
- checkWarnings (cmd , client )
143
+
144
+ err = checkWarnings (cmd , client )
145
+ if err != nil {
146
+ // Same as above
147
+ _ , _ = fmt .Fprintf (cmd .ErrOrStderr (),
148
+ cliui .Styles .Warn .Render ("check entitlement warnings error: %s" ), err )
149
+ _ , _ = fmt .Fprintln (cmd .ErrOrStderr ())
150
+ }
135
151
},
136
152
Example : formatExamples (
137
153
example {
@@ -468,9 +484,11 @@ func checkVersions(cmd *cobra.Command, client *codersdk.Client) error {
468
484
return nil
469
485
}
470
486
471
- clientVersion := buildinfo .Version ()
487
+ ctx , cancel := context .WithTimeout (cmd .Context (), 10 * time .Second )
488
+ defer cancel ()
472
489
473
- info , err := client .BuildInfo (cmd .Context ())
490
+ clientVersion := buildinfo .Version ()
491
+ info , err := client .BuildInfo (ctx )
474
492
// Avoid printing errors that are connection-related.
475
493
if codersdk .IsConnectionErr (err ) {
476
494
return nil
@@ -494,15 +512,21 @@ download the server version with: 'curl -L https://coder.com/install.sh | sh -s
494
512
return nil
495
513
}
496
514
497
- func checkWarnings (cmd * cobra.Command , client * codersdk.Client ) {
515
+ func checkWarnings (cmd * cobra.Command , client * codersdk.Client ) error {
498
516
if cliflag .IsSetBool (cmd , varNoFeatureWarning ) {
499
- return
517
+ return nil
500
518
}
501
- entitlements , err := client .Entitlements (cmd .Context ())
519
+
520
+ ctx , cancel := context .WithTimeout (cmd .Context (), 10 * time .Second )
521
+ defer cancel ()
522
+
523
+ entitlements , err := client .Entitlements (ctx )
502
524
if err != nil {
503
- return
525
+ return xerrors . Errorf ( "get entitlements to show warnings: %w" , err )
504
526
}
505
527
for _ , w := range entitlements .Warnings {
506
528
_ , _ = fmt .Fprintln (cmd .ErrOrStderr (), cliui .Styles .Warn .Render (w ))
507
529
}
530
+
531
+ return nil
508
532
}
0 commit comments