From d913ae80f9be09d4fdb20e3cfd23df071abf1fe6 Mon Sep 17 00:00:00 2001 From: Chen Asraf Date: Thu, 29 Jan 2026 14:21:21 +0200 Subject: [PATCH] feat: add version flag --- internal/cli/root.go | 4 ++++ main.go | 11 ++++++++++- version.txt | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 version.txt diff --git a/internal/cli/root.go b/internal/cli/root.go index 9c13b41..fcd3784 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -10,6 +10,9 @@ import ( ) var ( + // Version is set by main.go from embedded version.txt + Version string + // Global flags verbose bool dry bool @@ -66,6 +69,7 @@ func initConfig(cmd *cobra.Command, args []string) error { // Execute adds all child commands to the root command and sets flags appropriately func Execute() { + rootCmd.Version = Version if err := rootCmd.Execute(); err != nil { fmt.Fprintln(os.Stderr, "Error:", err.Error()) os.Exit(1) diff --git a/main.go b/main.go index 4c1a9f5..81ac9c8 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,16 @@ package main -import "github.com/chenasraf/tx/internal/cli" +import ( + _ "embed" + "strings" + + "github.com/chenasraf/tx/internal/cli" +) + +//go:embed version.txt +var version string func main() { + cli.Version = strings.TrimSpace(version) cli.Execute() } diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..7dea76e --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +1.0.1