@@ -515,7 +515,11 @@ func addTelemetryHeader(client *codersdk.Client, inv *clibase.Invocation) {
515
515
// InitClient sets client to a new client.
516
516
// It reads from global configuration files if flags are not set.
517
517
func (r * RootCmd ) InitClient (client * codersdk.Client ) clibase.MiddlewareFunc {
518
- return r .initClientInternal (client , false )
518
+ return clibase .Chain (
519
+ r .initClientInternal (client , false ),
520
+ // By default, we should print warnings in addition to initializing the client
521
+ r .PrintWarnings (client ),
522
+ )
519
523
}
520
524
521
525
func (r * RootCmd ) InitClientMissingTokenOK (client * codersdk.Client ) clibase.MiddlewareFunc {
@@ -575,7 +579,20 @@ func (r *RootCmd) initClientInternal(client *codersdk.Client, allowTokenMissing
575
579
client .SetLogBodies (true )
576
580
}
577
581
client .DisableDirectConnections = r .disableDirect
582
+ return next (inv )
583
+ }
584
+ }
585
+ }
578
586
587
+ func (r * RootCmd ) PrintWarnings (client * codersdk.Client ) clibase.MiddlewareFunc {
588
+ if client == nil {
589
+ panic ("client is nil" )
590
+ }
591
+ if r == nil {
592
+ panic ("root is nil" )
593
+ }
594
+ return func (next clibase.HandlerFunc ) clibase.HandlerFunc {
595
+ return func (inv * clibase.Invocation ) error {
579
596
// We send these requests in parallel to minimize latency.
580
597
var (
581
598
versionErr = make (chan error )
@@ -591,14 +608,14 @@ func (r *RootCmd) initClientInternal(client *codersdk.Client, allowTokenMissing
591
608
close (warningErr )
592
609
}()
593
610
594
- if err = <- versionErr ; err != nil {
611
+ if err : = <- versionErr ; err != nil {
595
612
// Just log the error here. We never want to fail a command
596
613
// due to a pre-run.
597
614
pretty .Fprintf (inv .Stderr , cliui .DefaultStyles .Warn , "check versions error: %s" , err )
598
615
_ , _ = fmt .Fprintln (inv .Stderr )
599
616
}
600
617
601
- if err = <- warningErr ; err != nil {
618
+ if err : = <- warningErr ; err != nil {
602
619
// Same as above
603
620
pretty .Fprintf (inv .Stderr , cliui .DefaultStyles .Warn , "check entitlement warnings error: %s" , err )
604
621
_ , _ = fmt .Fprintln (inv .Stderr )
0 commit comments