Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit04b5329

Browse files
committed
chore(cli): centralize upgrade message logic in defaultUpgradeMessage; simplify warning formatting; use releases URL on Windows
1 parent3d411dd commit04b5329

File tree

1 file changed

+44
-21
lines changed

1 file changed

+44
-21
lines changed

‎cli/root.go‎

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,14 +1361,37 @@ func SlimUnsupported(w io.Writer, cmd string) {
13611361
os.Exit(1)
13621362
}
13631363

1364-
funcdefaultUpgradeMessage(versionstring)string {
1365-
// Our installation script doesn't work on Windows, so instead we direct the user
1366-
// to the GitHub release page to download the latest installer.
1367-
version=strings.TrimPrefix(version,"v")
1368-
ifruntime.GOOS=="windows" {
1369-
returnfmt.Sprintf("download the server version from: https://github.com/coder/coder/releases/v%s",version)
1370-
}
1371-
returnfmt.Sprintf("download the server version with: 'curl -L https://coder.com/install.sh | sh -s -- --version %s'",version)
1364+
// defaultUpgradeMessage builds an appropriate upgrade message for the platform.
1365+
// Precedence:
1366+
// 1) If a custom upgrade message is provided by the server, use it.
1367+
// 2) If the server provides a dashboard URL (v2.19+) and the platform is not Windows,
1368+
// recommend the site-local install.sh.
1369+
// 3) On Windows, point to the tagged GitHub release page where binaries are published.
1370+
// 4) Otherwise, recommend the global install.sh with explicit version.
1371+
funcdefaultUpgradeMessage(version,dashboardURL,customUpgradeMessagestring)string {
1372+
ifcustomUpgradeMessage!="" {
1373+
returncustomUpgradeMessage
1374+
}
1375+
1376+
// Ensure canonical semver for comparisons and display
1377+
canonical:=semver.Canonical(version)
1378+
trimmed:=strings.TrimPrefix(canonical,"v")
1379+
1380+
// The site-local `install.sh` was introduced in v2.19.0.
1381+
ifdashboardURL!=""&&semver.Compare(semver.MajorMinor(canonical),"v2.19")>=0 {
1382+
// The site-local install.sh is only valid for macOS and Linux.
1383+
ifruntime.GOOS!="windows" {
1384+
returnfmt.Sprintf("download %s with: 'curl -fsSL %s/install.sh | sh'",canonical,dashboardURL)
1385+
}
1386+
// Fall through to Windows-specific suggestion below.
1387+
}
1388+
1389+
ifruntime.GOOS=="windows" {
1390+
// Link directly to the release page; Windows binaries are published there.
1391+
returnfmt.Sprintf("download the server version from: https://github.com/coder/coder/releases/v%s",trimmed)
1392+
}
1393+
1394+
returnfmt.Sprintf("download the server version with: 'curl -L https://coder.com/install.sh | sh -s -- --version %s'",trimmed)
13721395
}
13731396

13741397
// wrapTransportWithEntitlementsCheck adds a middleware to the HTTP transport
@@ -1407,19 +1430,19 @@ func wrapTransportWithVersionMismatchCheck(rt http.RoundTripper, inv *serpent.In
14071430
ifbuildinfo.VersionsMatch(clientVersion,serverVersion) {
14081431
return
14091432
}
1410-
upgradeMessage:=defaultUpgradeMessage(semver.Canonical(serverVersion))
1411-
ifserverInfo,err:=getBuildInfo(inv.Context());err==nil {
1412-
switch {
1413-
caseserverInfo.UpgradeMessage!="":
1414-
upgradeMessage=serverInfo.UpgradeMessage
1415-
// The site-local `install.sh` was introduced in v2.19.0
1416-
caseserverInfo.DashboardURL!=""&&semver.Compare(semver.MajorMinor(serverVersion),"v2.19")>=0:
1417-
upgradeMessage=fmt.Sprintf("download %s with: 'curl -fsSL %s/install.sh | sh'",serverVersion,serverInfo.DashboardURL)
1418-
}
1419-
}
1420-
fmtWarningText:="version mismatch: client %s, server %s\n%s"
1421-
fmtWarn:=pretty.Sprint(cliui.DefaultStyles.Warn,fmtWarningText)
1422-
warning:=fmt.Sprintf(fmtWarn,clientVersion,serverVersion,upgradeMessage)
1433+
vardashboardURL,customUpgradeMessagestring
1434+
ifserverInfo,err:=getBuildInfo(inv.Context());err==nil {
1435+
dashboardURL=serverInfo.DashboardURL
1436+
customUpgradeMessage=serverInfo.UpgradeMessage
1437+
}
1438+
upgradeMessage:=defaultUpgradeMessage(serverVersion,dashboardURL,customUpgradeMessage)
1439+
warning:=pretty.Sprintf(
1440+
cliui.DefaultStyles.Warn,
1441+
"version mismatch: client %s, server %s\n%s",
1442+
clientVersion,
1443+
serverVersion,
1444+
upgradeMessage,
1445+
)
14231446

14241447
_,_=fmt.Fprintln(inv.Stderr,warning)
14251448
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp