Skip to content

Commit

Permalink
Merge pull request #36 from harakeishi/fix/echo-version
Browse files Browse the repository at this point in the history
version表示機能の修正
  • Loading branch information
harakeishi committed Feb 26, 2022
2 parents 67dc66f + a332421 commit 4c28af8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ builds:
- windows
- darwin
ldflags:
- -s -w -X "main.version={{.Env.Version}}"
- -s -w -X github.com/harakeishi/whris/cmd.ver={{.Version}}
archives:
- replacements:
darwin: Darwin
Expand Down
11 changes: 5 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra"
)

var Ver = "dev"
var ver = "dev"
var rootCmd = &cobra.Command{
Use: "whris",
Short: "`whris` is Displays management information for IPs associated with the domain.",
Expand All @@ -22,12 +22,12 @@ var rootCmd = &cobra.Command{
os.Exit(1)
}
if version {
if strings.Contains(Ver, "dev") {
fmt.Println(Ver)
if !strings.Contains(ver, "dev") {
fmt.Println(ver)
return nil
}
if buildInfo, ok := debug.ReadBuildInfo(); ok {
fmt.Println(buildInfo.Main.Version)
fmt.Printf("%+v\n", buildInfo.Main)
return nil
}
fmt.Println("unknown")
Expand All @@ -47,8 +47,7 @@ var rootCmd = &cobra.Command{
},
}

func Execute(ver string) {
Ver = ver
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
Expand Down
6 changes: 1 addition & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import (
"github.com/harakeishi/whris/cmd"
)

var (
version = "dev"
)

func main() {
cmd.Execute(version)
cmd.Execute()
}

0 comments on commit 4c28af8

Please sign in to comment.