diff --git a/cmd/root.go b/cmd/root.go index b3bf877..fae8e39 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -8,6 +8,8 @@ import ( "github.com/spf13/cobra" ) +var Version string + func Execute() error { configFile := resolveConfigFile() cfg, commands, err := loadConfig(configFile) @@ -22,6 +24,8 @@ func Execute() error { } rootCmd.PersistentFlags().String("wand-file", "", "path to wand config file (overrides discovery)") + rootCmd.Version = Version + rootCmd.SetVersionTemplate("{{.Version}}\n") if main, ok := commands["main"]; ok { rootCmd.Short = main.Description diff --git a/main.go b/main.go index 7061d0f..cdf1008 100644 --- a/main.go +++ b/main.go @@ -1,13 +1,19 @@ package main import ( + _ "embed" "fmt" "os" + "strings" "github.com/chenasraf/wand/cmd" ) +//go:embed version.txt +var version string + func main() { + cmd.Version = strings.TrimSpace(version) if err := cmd.Execute(); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..6261a05 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +1.3.1 \ No newline at end of file