Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit a0db320

Browse files
committed
Do not strip "v" prefix from version when printing
I noticed this when building the binary; `internal.Version` is set to `v2.0.0-beta.4`, to match the tag. ```bash GIT_TAG=v2.0.0-beta.4 make COMPOSE_BINARY=bin/docker-compose -f builder.Makefile compose-plugin \ GOOS=linux \ GOARCH=amd64 \ CGO_ENABLED=0 \ go build \ -trimpath \ -ldflags="-s -w -X github.com/docker/compose-cli/internal.Version=v2.0.0-beta.4" \ -o bin/docker-compose \ ./cmd ``` However, the binary has the `v` prefix stripped (which caused a check to fail when packaging): ```bash /root/rpmbuild/BUILDROOT/docker-compose-plugin-2.0.0.beta.4-0.fc34.x86_64/usr/libexec/docker/cli-plugins/docker-compose docker-cli-plugin-metadata ++ awk '{ gsub(/[",:]/,"")}; $1 == "Version" { print $2 }' + ver=2.0.0-beta.4 + test 2.0.0-beta.4 = v2.0.0-beta.4 FAIL: docker-compose version (2.0.0-beta.4) did not match ``` This also looks inconsistent with other binaries and plugins we ship: ```bash docker info --format '{{json .ClientInfo.Plugins}}' | jq . [ { "SchemaVersion": "0.1.0", "Vendor": "Docker Inc.", "Version": "v0.5.1-docker", "ShortDescription": "Build with BuildKit", "Name": "buildx", "Path": "/usr/libexec/docker/cli-plugins/docker-buildx" }, { "SchemaVersion": "0.1.0", "Vendor": "Docker Inc.", "Version": "2.0.0-beta.4", "ShortDescription": "Docker Compose", "Name": "compose", "Path": "/usr/libexec/docker/cli-plugins/docker-compose" }, { "SchemaVersion": "0.1.0", "Vendor": "Docker Inc.", "Version": "v0.8.0", "ShortDescription": "Docker Scan", "Name": "scan", "Path": "/usr/libexec/docker/cli-plugins/docker-scan" } ] ``` Perhaps there was a specific reason for this, but thought I'd open this PR for discussion (if the v-prefix should not be there, perhaps we should isntead strip it when setting the version). Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 8d2ea5f commit a0db320

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

cli/cmd/version.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,16 @@ func runVersion(cmd *cobra.Command) error {
5757
var versionString string
5858
var err error
5959
format := strings.ToLower(strings.ReplaceAll(cmd.Flag(formatOpt).Value.String(), " ", ""))
60-
displayedVersion := strings.TrimPrefix(internal.Version, "v")
6160
// Replace is preferred in this case to keep the order.
6261
switch format {
6362
case formatter.PRETTY, "":
6463
versionString, err = getOutFromMoby(cmd, fixedPrettyArgs(os.Args[1:])...)
6564
versionString = strings.Replace(versionString,
66-
"\n Version:", "\n Cloud integration: "+displayedVersion+"\n Version:", 1)
65+
"\n Version:", "\n Cloud integration: "+internal.Version+"\n Version:", 1)
6766
case formatter.JSON, formatter.TemplateLegacyJSON: // Try to catch full JSON formats
6867
versionString, err = getOutFromMoby(cmd, fixedJSONArgs(os.Args[1:])...)
6968
versionString = strings.Replace(versionString,
70-
`"Version":`, fmt.Sprintf(`"CloudIntegration":%q,"Version":`, displayedVersion), 1)
69+
`"Version":`, fmt.Sprintf(`"CloudIntegration":%q,"Version":`, internal.Version), 1)
7170
default:
7271
versionString, err = getOutFromMoby(cmd)
7372
}

cmd/compose/version.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package compose
1818

1919
import (
2020
"fmt"
21-
"strings"
2221

2322
"github.com/spf13/cobra"
2423

@@ -52,14 +51,13 @@ func versionCommand() *cobra.Command {
5251
}
5352

5453
func runVersion(opts versionOptions) {
55-
displayedVersion := strings.TrimPrefix(internal.Version, "v")
5654
if opts.short {
57-
fmt.Println(displayedVersion)
55+
fmt.Println(internal.Version)
5856
return
5957
}
6058
if opts.format == formatter.JSON {
61-
fmt.Printf(`{"version":"%s"}\n`, displayedVersion)
59+
fmt.Printf(`{"version":%q}\n`, internal.Version)
6260
return
6361
}
64-
fmt.Printf("Docker Compose version %s\n", displayedVersion)
62+
fmt.Println("Docker Compose version", internal.Version)
6563
}

cmd/main.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
package main
1818

1919
import (
20-
"strings"
21-
2220
dockercli "github.com/docker/cli/cli"
2321
"github.com/docker/cli/cli-plugins/manager"
2422
"github.com/docker/cli/cli-plugins/plugin"
@@ -58,6 +56,6 @@ func main() {
5856
manager.Metadata{
5957
SchemaVersion: "0.1.0",
6058
Vendor: "Docker Inc.",
61-
Version: strings.TrimPrefix(internal.Version, "v"),
59+
Version: internal.Version,
6260
})
6361
}

0 commit comments

Comments
 (0)