Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ out/
refrax
tmp-copy/
tmp/
dist/
5 changes: 5 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ builds:
- linux
- windows
- darwin
ldflags:
- -s -w
- -X github.com/cqfn/refrax/internal/util.version={{.Version}}
- -X github.com/cqfn/refrax/internal/util.commit={{.FullCommit}}
- -X github.com/cqfn/refrax/internal/util.datetime={{.Date}}

archives:
- formats: [tar.gz]
Expand Down
3 changes: 3 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"github.com/cqfn/refrax/internal/client"
"github.com/cqfn/refrax/internal/util"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -39,5 +40,7 @@ func NewRootCmd(out, _ io.Writer) *cobra.Command {
newRefactorCmd(&params),
newStartCmd(),
)
root.Version = util.Version()
root.SetVersionTemplate("refrax {{.Version}}\n")
return root
}
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ module github.com/cqfn/refrax

go 1.24.2

require github.com/spf13/cobra v1.9.1
require (
github.com/google/uuid v1.3.0
github.com/spf13/cobra v1.9.1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dlclark/regexp2 v1.10.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
36 changes: 36 additions & 0 deletions internal/util/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package util

import (
"strings"
)

const (
defaultVersion = "dev"
defaultCommit = "none"
defaultDatetime = "none"
)

var (
// Use the following command to change this value:
// go build -ldflags "-X github.com/cqfn/refrax/internal/util.version=<version>"
version string = defaultVersion

// Use the following command to change this value:
// go build -ldflags "-X github.com/cqfn/refrax/internal/util.commit=<commit-hash>"
commit string = defaultCommit

// Use the following command to change this value:
// go build -ldflags "-X github.com/cqfn/refrax/internal/util.datetime=<date-time>"
datetime string = defaultDatetime
)

func Version() string {
parts := []string{version}
if commit != defaultCommit {
parts = append(parts, "commit", commit)
}
if datetime != defaultDatetime {
parts = append(parts, "built at", datetime)
}
return strings.Join(parts, " ")
}
12 changes: 12 additions & 0 deletions internal/util/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package util

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestCurrentVersion(t *testing.T) {
datetime = "2024-01-01T00:00:00Z"
assert.Equal(t, "dev built at "+datetime, Version())
}
Loading