| 1 | package cmd |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | |
| 6 | "the-valley/flow/internal/config" |
| 7 | "the-valley/flow/internal/git" |
| 8 | "github.com/spf13/cobra" |
| 9 | ) |
| 10 | |
| 11 | var initCmd = &cobra.Command{ |
| 12 | Use: "init", |
| 13 | Short: "Initialize flow config", |
| 14 | Long: `Scaffolds default config.json and prompt.md template. |
| 15 | |
| 16 | If run inside a git repository, writes them in the repo's .klaus/ (or over the |
| 17 | ones in .valley/flow/, where a repo keeps them there). |
| 18 | If run outside a git repository, writes the host config, ~/.klaus/config.json |
| 19 | (or ~/.valley/flow/config.json, where the host keeps it).`, |
| 20 | RunE: func(cmd *cobra.Command, args []string) error { |
| 21 | root, _ := git.RepoRoot() |
| 22 | |
| 23 | if root != "" { |
| 24 | configPath, promptPath, err := config.Init(root) |
| 25 | if err != nil { |
| 26 | return err |
| 27 | } |
| 28 | fmt.Println("Initialized flow config:") |
| 29 | fmt.Printf(" %s โ configuration\n", configPath) |
| 30 | fmt.Printf(" %s โ system prompt template\n", promptPath) |
| 31 | } else { |
| 32 | path, err := config.InitGlobal() |
| 33 | if err != nil { |
| 34 | return err |
| 35 | } |
| 36 | fmt.Println("Initialized global flow config:") |
| 37 | fmt.Printf(" %s โ configuration\n", path) |
| 38 | } |
| 39 | return nil |
| 40 | }, |
| 41 | } |
| 42 | |
| 43 | func init() { |
| 44 | rootCmd.AddCommand(initCmd) |
| 45 | } |