Add support for bd --version flag

- Add -v, --version flag to root command
- Both bd --version and bd -v now print version info
- bd version subcommand continues to work as before
- Add tests for both flag variants

Amp-Thread-ID: https://ampcode.com/threads/T-583f9ef8-c358-48c5-91cf-c23a91bab9d7
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Steve Yegge
2025-11-05 17:37:48 -08:00
parent 07d2c0ccc6
commit 34ba064dcc
2 changed files with 78 additions and 0 deletions

View File

@@ -94,12 +94,24 @@ func init() {
rootCmd.PersistentFlags().BoolVar(&noAutoImport, "no-auto-import", false, "Disable automatic JSONL import when newer than DB")
rootCmd.PersistentFlags().BoolVar(&sandboxMode, "sandbox", false, "Sandbox mode: disables daemon and auto-sync")
rootCmd.PersistentFlags().BoolVar(&noDb, "no-db", false, "Use no-db mode: load from JSONL, no SQLite")
// Add --version flag to root command (same behavior as version subcommand)
rootCmd.Flags().BoolP("version", "v", false, "Print version information")
}
var rootCmd = &cobra.Command{
Use: "bd",
Short: "bd - Dependency-aware issue tracker",
Long: `Issues chained together like beads. A lightweight issue tracker with first-class dependency support.`,
Run: func(cmd *cobra.Command, args []string) {
// Handle --version flag on root command
if v, _ := cmd.Flags().GetBool("version"); v {
fmt.Printf("bd version %s (%s)\n", Version, Build)
return
}
// No subcommand - show help
_ = cmd.Help()
},
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// Apply viper configuration if flags weren't explicitly set
// Priority: flags > viper (config file + env vars) > defaults