Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 636d5db

Browse files
committed
remove race condition
1 parent 51301d9 commit 636d5db

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

buildinfo/buildinfo_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ func TestBuildInfo(t *testing.T) {
5656
v2: "v1.2.3",
5757
expectMatch: true,
5858
},
59+
// Our CI instance uses a "-devel" prerelease
60+
// flag. This is not the same as a developer WIP build.
61+
{
62+
name: "DevelPreleaseNotIgnored",
63+
v1: "v1.1.1-devel+123abac",
64+
v2: "v1.2.3",
65+
expectMatch: false,
66+
},
5967
{
6068
name: "MajorMismatch",
6169
v1: "v1.2.3",

cli/root.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"net/url"
66
"os"
7+
"strconv"
78
"strings"
89
"time"
910

@@ -41,12 +42,12 @@ const (
4142
varForceTty = "force-tty"
4243
notLoggedInMessage = "You are not logged in. Try logging in using 'coder login <url>'."
4344

44-
envNoVersionCheck = "CODER_NO_VERSION_WARNING"
45+
noVersionCheckFlag = "no-version-warning"
46+
envNoVersionCheck = "CODER_NO_VERSION_WARNING"
4547
)
4648

4749
var (
4850
errUnauthenticated = xerrors.New(notLoggedInMessage)
49-
varSuppressVersion = false
5051
envSessionToken = "CODER_SESSION_TOKEN"
5152
)
5253

@@ -60,6 +61,8 @@ func init() {
6061
}
6162

6263
func Root() *cobra.Command {
64+
var varSuppressVersion bool
65+
6366
cmd := &cobra.Command{
6467
Use: "coder",
6568
SilenceErrors: true,
@@ -127,7 +130,7 @@ func Root() *cobra.Command {
127130
cmd.SetUsageTemplate(usageTemplate())
128131

129132
cmd.PersistentFlags().String(varURL, "", "Specify the URL to your deployment.")
130-
cliflag.BoolVarP(cmd.Flags(), &varSuppressVersion, "no-version-warning", "", envNoVersionCheck, false, "Suppress warning when client and server versions do not match.")
133+
cliflag.BoolVarP(cmd.PersistentFlags(), &varSuppressVersion, noVersionCheckFlag, "", envNoVersionCheck, false, "Suppress warning when client and server versions do not match.")
131134
cliflag.String(cmd.PersistentFlags(), varToken, "", envSessionToken, "", fmt.Sprintf("Specify an authentication token. For security reasons setting %s is preferred.", envSessionToken))
132135
cliflag.String(cmd.PersistentFlags(), varAgentToken, "", "CODER_AGENT_TOKEN", "", "Specify an agent authentication token.")
133136
_ = cmd.PersistentFlags().MarkHidden(varAgentToken)
@@ -364,7 +367,8 @@ func FormatCobraError(err error, cmd *cobra.Command) string {
364367
}
365368

366369
func checkVersions(cmd *cobra.Command, client *codersdk.Client) error {
367-
if varSuppressVersion {
370+
flag := cmd.Flag("no-version-warning")
371+
if suppress, _ := strconv.ParseBool(flag.Value.String()); suppress {
368372
return nil
369373
}
370374

0 commit comments

Comments
 (0)