feat: IMP-13 — add version command with build-time variables
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user