Skip to content

Commit f420a92

Browse files
authored
fix: remove v prefix from version (#379)
The prefix is not used in pre-built packages. This removes it also when using go install.
1 parent 99522a1 commit f420a92

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
184184
### Fixed
185185

186186
- Use correct currency symbol, `` instead of `$`, in human output of `account show`.
187+
- Remove `v` prefix from version in `version` command output and User-Agent header
187188

188189
## [3.0.0] - 2023-10-18
189190

internal/config/config.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"path/filepath"
7+
"regexp"
78
"runtime/debug"
89
"strings"
910
"time"
@@ -216,6 +217,15 @@ func (s *Config) CreateService() (internal.AllServices, error) {
216217
}
217218

218219
func GetVersion() string {
220+
version := getVersion()
221+
re := regexp.MustCompile(`v[0-9]+\.[0-9]+\.[0-9]+.*`)
222+
if re.MatchString(version) {
223+
return version[1:]
224+
}
225+
return version
226+
}
227+
228+
func getVersion() string {
219229
// Version was overridden during the build
220230
if Version != "dev" {
221231
return Version

internal/config/config_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,31 @@ func TestConfig_Load(t *testing.T) {
3333
assert.NotEmpty(t, cfg.GetString("username"))
3434
assert.NotEmpty(t, cfg.GetString("password"))
3535
}
36+
37+
func TestVersion(t *testing.T) {
38+
tests := []struct {
39+
name string
40+
expected string
41+
version string
42+
}{
43+
{
44+
name: "Removes v prefix",
45+
version: "v1.2.3",
46+
expected: "1.2.3",
47+
},
48+
{
49+
name: "Removes v prefix with suffix",
50+
version: "v1.2.3-rc1",
51+
expected: "1.2.3-rc1",
52+
},
53+
}
54+
for _, test := range tests {
55+
test := test
56+
t.Run(test.name, func(t *testing.T) {
57+
t.Parallel()
58+
Version = test.version
59+
actual := GetVersion()
60+
assert.Equal(t, test.expected, actual)
61+
})
62+
}
63+
}

0 commit comments

Comments
 (0)