Skip to content

Commit 7b1be43

Browse files
committed
fix version formatting
1 parent 180212c commit 7b1be43

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

cli/root.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -835,14 +835,14 @@ func (r *RootCmd) checkVersions(i *clibase.Invocation, client *codersdk.Client,
835835
}
836836

837837
if !buildinfo.VersionsMatch(clientVersion, serverInfo.Version) {
838-
upgradeMessage := defaultUpgradeMessage()
838+
upgradeMessage := defaultUpgradeMessage(strings.TrimPrefix(serverInfo.CanonicalVersion(), "v"))
839839
if serverInfo.UpgradeMessage != "" {
840840
upgradeMessage = serverInfo.UpgradeMessage
841841
}
842842

843843
fmtWarningText := "version mismatch: client %s, server %s\n%s"
844844
fmtWarn := pretty.Sprint(cliui.DefaultStyles.Warn, fmtWarningText)
845-
warning := fmt.Sprintf(fmtWarn, clientVersion, strings.TrimPrefix(serverInfo.CanonicalVersion(), "v"), upgradeMessage)
845+
warning := fmt.Sprintf(fmtWarn, clientVersion, serverInfo.Version, upgradeMessage)
846846

847847
_, _ = fmt.Fprint(i.Stderr, warning)
848848
_, _ = fmt.Fprintln(i.Stderr)
@@ -1218,12 +1218,11 @@ func SlimUnsupported(w io.Writer, cmd string) {
12181218
os.Exit(1)
12191219
}
12201220

1221-
func defaultUpgradeMessage() string {
1221+
func defaultUpgradeMessage(serverVersion string) string {
12221222
// Our installation script doesn't work on Windows, so instead we direct the user
12231223
// to the GitHub release page to download the latest installer.
1224-
version := buildinfo.Version()
12251224
if runtime.GOOS == "windows" {
1226-
return fmt.Sprintf("download the server version from: https://github.com/coder/coder/releases/v%s", version)
1225+
return fmt.Sprintf("download the server version from: https://github.com/coder/coder/releases/v%s", serverVersion)
12271226
}
1228-
return fmt.Sprintf("download the server version with: 'curl -L https://coder.com/install.sh | sh -s -- --version %s'", version)
1227+
return fmt.Sprintf("download the server version with: 'curl -L https://coder.com/install.sh | sh -s -- --version %s'", serverVersion)
12291228
}

cli/root_internal_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func Test_checkVersions(t *testing.T) {
135135
err = r.checkVersions(inv, client, "v2.0.0")
136136
require.NoError(t, err)
137137

138-
fmtOutput := fmt.Sprintf("version mismatch: client v2.0.0, server 1.0.0\n%s", expectedUpgradeMessage)
138+
fmtOutput := fmt.Sprintf("version mismatch: client v2.0.0, server v1.0.0\n%s", expectedUpgradeMessage)
139139
expectedOutput := fmt.Sprintln(pretty.Sprint(cliui.DefaultStyles.Warn, fmtOutput))
140140
require.Equal(t, expectedOutput, buf.String())
141141
})
@@ -173,7 +173,7 @@ func Test_checkVersions(t *testing.T) {
173173
err = r.checkVersions(inv, client, "v2.0.0")
174174
require.NoError(t, err)
175175

176-
fmtOutput := fmt.Sprintf("version mismatch: client v2.0.0, server 1.0.0\n%s", defaultUpgradeMessage())
176+
fmtOutput := fmt.Sprintf("version mismatch: client v2.0.0, server v1.0.0\n%s", defaultUpgradeMessage("1.0.0"))
177177
expectedOutput := fmt.Sprintln(pretty.Sprint(cliui.DefaultStyles.Warn, fmtOutput))
178178
require.Equal(t, expectedOutput, buf.String())
179179
})

0 commit comments

Comments
 (0)