Skip to content

Commit 423ab8b

Browse files
committed
move trimming into helper
1 parent 7b1be43 commit 423ab8b

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

cli/root.go

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

837837
if !buildinfo.VersionsMatch(clientVersion, serverInfo.Version) {
838-
upgradeMessage := defaultUpgradeMessage(strings.TrimPrefix(serverInfo.CanonicalVersion(), "v"))
838+
upgradeMessage := defaultUpgradeMessage(serverInfo.CanonicalVersion())
839839
if serverInfo.UpgradeMessage != "" {
840840
upgradeMessage = serverInfo.UpgradeMessage
841841
}
@@ -1218,11 +1218,12 @@ func SlimUnsupported(w io.Writer, cmd string) {
12181218
os.Exit(1)
12191219
}
12201220

1221-
func defaultUpgradeMessage(serverVersion string) string {
1221+
func defaultUpgradeMessage(version 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 = strings.TrimPrefix(version, "v")
12241225
if runtime.GOOS == "windows" {
1225-
return fmt.Sprintf("download the server version from: https://github.com/coder/coder/releases/v%s", serverVersion)
1226+
return fmt.Sprintf("download the server version from: https://github.com/coder/coder/releases/v%s", version)
12261227
}
1227-
return fmt.Sprintf("download the server version with: 'curl -L https://coder.com/install.sh | sh -s -- --version %s'", serverVersion)
1228+
return fmt.Sprintf("download the server version with: 'curl -L https://coder.com/install.sh | sh -s -- --version %s'", version)
12281229
}

cli/root_internal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 v1.0.0\n%s", defaultUpgradeMessage("1.0.0"))
176+
fmtOutput := fmt.Sprintf("version mismatch: client v2.0.0, server v1.0.0\n%s", defaultUpgradeMessage("v1.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)