Skip to content

Commit

Permalink
fix: Fixed build information in the CLI version command
Browse files Browse the repository at this point in the history
The commit fixes issue #17 by updating the build information in the CLI version command. The build information now includes the commit date and commit hash. The changes were made in the version.go and .goreleaser.yaml files.
  • Loading branch information
tbckr committed Mar 22, 2023
1 parent 62b9aef commit b8ac964
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ builds:
- goos: windows
goarch: arm
ldflags:
- "-X 'sgpt.Version={{.Version}}'"
- -X 'github.com/tbckr/sgpt/internal/buildinfo.version={{.Version}}'
- -X 'github.com/tbckr/sgpt/internal/buildinfo.commit={{.Commit}}'
- -X 'github.com/tbckr/sgpt/internal/buildinfo.commitDate={{.CommitDate}}'

archives:
- format: tar.gz
Expand Down
9 changes: 6 additions & 3 deletions cmd/sgpt/cli/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"

"github.com/peterbourgon/ff/v3/ffcli"
"github.com/tbckr/sgpt"
"github.com/tbckr/sgpt/internal/buildinfo"
)

var versionCmd = &ffcli.Command{
Expand All @@ -34,15 +34,18 @@ func runVersion(_ context.Context, _ []string) error {
var output string
if versionArgs.json {
versionMap := map[string]string{
"version": sgpt.Version,
"version": buildinfo.Version(),
"commit": buildinfo.Commit(),
"commitDate": buildinfo.CommitDate(),
}
byteData, err := json.Marshal(versionMap)
if err != nil {
return err
}
output = string(byteData)
} else {
output = sgpt.Version
output = fmt.Sprintf("version: %s\ncommit: %s\ncommitDate: %s",
buildinfo.Version(), buildinfo.Commit(), buildinfo.CommitDate())
}
if _, err := fmt.Fprintln(stdout, output); err != nil {
return err
Expand Down
19 changes: 19 additions & 0 deletions internal/buildinfo/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package buildinfo

var (
version = "dev"
commit = "unset"
commitDate = "unset"
)

func Version() string {
return version
}

func Commit() string {
return commit
}

func CommitDate() string {
return commitDate
}
1 change: 0 additions & 1 deletion sgpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var (
ErrMissingAPIKey = fmt.Errorf("%s env variable is not set", envKeyOpenAIApi)
ErrUnsupportedModifier = errors.New("unsupported modifier")
ErrChatNotSupported = errors.New("chat is not supported with this model")
Version = "dev"
)

type CompletionOptions struct {
Expand Down

0 comments on commit b8ac964

Please sign in to comment.