package cli import ( "path/filepath" "github.com/thepeterstone/claudomator/internal/config" "github.com/spf13/cobra" ) var ( cfgFile string verbose bool cfg *config.Config ) func NewRootCmd() *cobra.Command { cfg = config.Default() cmd := &cobra.Command{ Use: "claudomator", Short: "Automation toolkit for Claude Code", Long: "Claudomator captures tasks, dispatches them to Claude Code, and reports results.", } cmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default $HOME/.claudomator/config.toml)") cmd.PersistentFlags().StringVar(&cfg.DataDir, "data-dir", cfg.DataDir, "data directory") cmd.PersistentFlags().StringVar(&cfg.ClaudeBinaryPath, "claude-bin", cfg.ClaudeBinaryPath, "path to claude binary") cmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose output") // Re-derive DBPath and LogDir after flags are parsed, so --data-dir takes effect. cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error { cfg.DBPath = filepath.Join(cfg.DataDir, "claudomator.db") cfg.LogDir = filepath.Join(cfg.DataDir, "executions") return nil } cmd.AddCommand( newRunCmd(), newServeCmd(), newListCmd(), newStatusCmd(), newInitCmd(), newLogsCmd(), newStartCmd(), ) return cmd } func Execute() error { return NewRootCmd().Execute() }