package cmd import ( "fmt" "github.com/spf13/cobra" ) // version and commit hold the values injected at release build time // (via `-ldflags -X main.version=... -X main.commit=...` propagated through // SetVersionInfo) or the defaults below for local development builds. // // `version` is the release tag verbatim (e.g. "v0.6.1-rc.1"). For dev // builds it is the literal "dev". `commit` is the full git SHA at build // time, or empty when not injected. var ( version = "dev" commit = "" ) var rootCmd = &cobra.Command{ Use: "ctask", Short: "Create and manage AI-agent task workspaces", Long: "ctask is a local CLI that creates and manages named AI-agent task workspaces so developers can start, resume, and organize work more safely and predictably.", } func Execute() error { return rootCmd.Execute() } // SetVersionInfo is called from main() before Execute() to forward the // build-time-injected version and commit into the cmd package. Pass empty // strings to keep the package defaults. func SetVersionInfo(v, c string) { if v != "" { version = v } if c != "" { commit = c } applyVersionTemplate() } // applyVersionTemplate rebuilds Cobra's --version output from the current // version/commit values. Format: // // ctask v0.6.1-rc.1 (abcdef1) // tagged build, commit known // ctask v0.6.1-rc.1 // tagged build, no commit injected // ctask dev // local build func applyVersionTemplate() { rootCmd.Version = version var line string if commit != "" { short := commit if len(short) > 7 { short = short[:7] } line = fmt.Sprintf("ctask %s (%s)\n", version, short) } else { line = fmt.Sprintf("ctask %s\n", version) } rootCmd.SetVersionTemplate(line) } func init() { applyVersionTemplate() }