Skip to content

Commit

Permalink
Update version management
Browse files Browse the repository at this point in the history
  • Loading branch information
fjammes committed Sep 4, 2023
1 parent 224ab3b commit ec2d936
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion txeh/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var rootCmd = &cobra.Command{
| |___ _____| |__
| __\ \/ / _ \ '_ \
| |_ > < __/ | | |
\__/_/\_\___|_| |_| v` + Version + `
\__/_/\_\___|_| |_| Version: ` + VersionFromBuild() + `
Add, remove and re-associate hostname entries in your /etc/hosts file.
Read more including usage as a Go library at https://github.com/txn2/txeh`,
Expand Down
23 changes: 22 additions & 1 deletion txeh/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"runtime/debug"

"github.com/spf13/cobra"
)
Expand All @@ -17,6 +18,26 @@ var versionCmd = &cobra.Command{
Short: "Print the version number of txeh",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("txeh Version %s\n", Version)
version := VersionFromBuild()
fmt.Printf("txeh Version: %s\n", version)
},
}

// Version returns the version of txeh binary
func VersionFromBuild() (version string) {
// Version is managed with goreleaser
if Version != "0.0.0" {
return Version
}
// Version is managed by "go install"
b, ok := debug.ReadBuildInfo()
if !ok {
return "unknown"
}
if b == nil {
version = "nil"
} else {
version = b.Main.Version
}
return version
}

0 comments on commit ec2d936

Please sign in to comment.