diff --git a/CHANGELOG.md b/CHANGELOG.md index 430a725..25a52e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ How to release a new version: - Manually release new version. ## [Unreleased] +### Added +- Use `debug.ReadBuildInfo` to get correct version. +- Print to stderr on error. + ### Removed - `openapi compose`, `repo init`, `repo template` commands. diff --git a/cmd/tea/gen_id.go b/cmd/tea/gen_id.go index 99e3d81..9a3b5c4 100644 --- a/cmd/tea/gen_id.go +++ b/cmd/tea/gen_id.go @@ -2,7 +2,6 @@ package main import ( "bytes" - "errors" "fmt" "go/ast" "go/parser" @@ -38,14 +37,8 @@ Example: RefreshToken uint64 ) `, - Run: func(cmd *cobra.Command, args []string) { - if err := runGenerateIDs(genIDOptions.SourceFilePath, genIDOptions.OutputFilePath); err != nil { - e := &cmderrors.CommandError{} - if errors.As(err, &e) { - os.Exit(e.Code) - } - os.Exit(-1) - } + RunE: func(cmd *cobra.Command, args []string) error { + return runGenerateIDs(genIDOptions.SourceFilePath, genIDOptions.OutputFilePath) }, } diff --git a/cmd/tea/main.go b/cmd/tea/main.go index 5535f55..363fe3f 100644 --- a/cmd/tea/main.go +++ b/cmd/tea/main.go @@ -1,12 +1,20 @@ package main -import "os" +import ( + "errors" + "os" + + cmderrors "go.strv.io/tea/pkg/errors" +) func main() { // Execute adds all child commands to the root command and sets flags appropriately. // This is called by main.main(). It only needs to happen once to the rootCmd. if err := rootCmd.Execute(); err != nil { - // TODO: Log the error. + e := &cmderrors.CommandError{} + if errors.As(err, &e) { + os.Exit(e.Code) + } os.Exit(1) } } diff --git a/cmd/tea/version.go b/cmd/tea/version.go index c690737..f26a990 100644 --- a/cmd/tea/version.go +++ b/cmd/tea/version.go @@ -2,12 +2,11 @@ package main import ( "fmt" + "runtime/debug" "github.com/spf13/cobra" ) -var version = "0.0.0" // version is set during build - var ( versionCmd = &cobra.Command{ Use: "version", @@ -19,6 +18,11 @@ Example: Provided by ` + colorLinkSTRV, Run: func(cmd *cobra.Command, args []string) { + version := "unknown" + buildInfo, ok := debug.ReadBuildInfo() + if ok { + version = buildInfo.Main.Version + } _, _ = fmt.Println(version) }, }