From 779da6ddfdd8f0d23d500493c850792c85635f98 Mon Sep 17 00:00:00 2001 From: Joakim Date: Thu, 19 Feb 2026 13:38:25 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20IMP-13=20=E2=80=94=20add=20version=20co?= =?UTF-8?q?mmand=20with=20build-time=20variables?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit opal version (and opal --version) prints version, commit, and build date. Values are set via ldflags at build time; defaults to "dev" for local builds. VERSION file added at 0.1.0. Co-Authored-By: Claude Opus 4.6 --- opal-task/VERSION | 1 + opal-task/cmd/root.go | 9 +++++++-- opal-task/cmd/version.go | 26 ++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 opal-task/VERSION create mode 100644 opal-task/cmd/version.go diff --git a/opal-task/VERSION b/opal-task/VERSION new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/opal-task/VERSION @@ -0,0 +1 @@ +0.1.0 diff --git a/opal-task/cmd/root.go b/opal-task/cmd/root.go index dacf6b7..ee46380 100644 --- a/opal-task/cmd/root.go +++ b/opal-task/cmd/root.go @@ -32,6 +32,7 @@ var commandNames = []string{ "add", "done", "modify", "delete", "start", "stop", "count", "projects", "tags", "info", "edit", "server", "sync", "reports", "setup", + "version", } // Report names (dynamically populated) @@ -47,9 +48,9 @@ var commandsWithModifiers = map[string]bool{ } var rootCmd = &cobra.Command{ - Use: "opal", + Use: "opal [filter] [command|report] [modifiers]", Short: "Opal task manager - taskwarrior-inspired CLI task management", - Long: `Opal is a powerful command-line task manager inspired by taskwarrior. + Long: `Opal is a powerful command-line task manager. It supports filtering, tags, priorities, projects, and recurring tasks.`, Run: func(cmd *cobra.Command, args []string) { // Default behavior: run configured default report (defaults to "list") @@ -218,6 +219,10 @@ func init() { rootCmd.AddCommand(infoCmd) rootCmd.AddCommand(editCmd) rootCmd.AddCommand(reportsCmd) + rootCmd.AddCommand(versionCmd) + + // Enable --version flag on root command + rootCmd.Version = Version // Add report commands dynamically reportCommands := CreateReportCommands() diff --git a/opal-task/cmd/version.go b/opal-task/cmd/version.go new file mode 100644 index 0000000..845e740 --- /dev/null +++ b/opal-task/cmd/version.go @@ -0,0 +1,26 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +// Set via ldflags at build time: +// +// go build -ldflags "-X git.jnss.me/joakim/opal/cmd.Version=$(cat VERSION) +// -X git.jnss.me/joakim/opal/cmd.Commit=$(git rev-parse --short HEAD) +// -X git.jnss.me/joakim/opal/cmd.BuildDate=$(date -u +%Y-%m-%d)" +var ( + Version = "dev" + Commit = "unknown" + BuildDate = "unknown" +) + +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Print version information", + Run: func(cmd *cobra.Command, args []string) { + fmt.Printf("opal %s (%s) built %s\n", Version, Commit, BuildDate) + }, +}