Skip to content

Commit

Permalink
fix: log errors, correct version from BuildInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Fazt01 committed Aug 16, 2024
1 parent 420ff4f commit 8433586
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
11 changes: 2 additions & 9 deletions cmd/tea/gen_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"bytes"
"errors"
"fmt"
"go/ast"
"go/parser"
Expand Down Expand Up @@ -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)
},
}

Expand Down
12 changes: 10 additions & 2 deletions cmd/tea/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
8 changes: 6 additions & 2 deletions cmd/tea/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
},
}
Expand Down

0 comments on commit 8433586

Please sign in to comment.