summaryrefslogtreecommitdiff
path: root/internal/cli/root.go
blob: 75ec393c8da367fbe0c5913aa503ca1122fed477 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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()
}