gunk-dev/the-valley

init.go

sourcecfedff357a41main's published tip history
1.0 KiB
1package cmd
2
3import (
4 "fmt"
5
6 "the-valley/flow/internal/config"
7 "the-valley/flow/internal/git"
8 "github.com/spf13/cobra"
9)
10
11var initCmd = &cobra.Command{
12 Use: "init",
13 Short: "Initialize flow config",
14 Long: `Scaffolds a .klaus/ directory with default config.json and prompt.md template.
15
16If run inside a git repository, creates .klaus/ in the repo root.
17If run outside a git repository, creates ~/.klaus/config.json for global configuration.`,
18 RunE: func(cmd *cobra.Command, args []string) error {
19 root, _ := git.RepoRoot()
20
21 if root != "" {
22 if err := config.Init(root); err != nil {
23 return err
24 }
25 fmt.Println("Initialized .klaus/ directory:")
26 fmt.Println(" .klaus/config.json โ€” configuration")
27 fmt.Println(" .klaus/prompt.md โ€” system prompt template")
28 } else {
29 if err := config.InitGlobal(); err != nil {
30 return err
31 }
32 fmt.Println("Initialized global flow config:")
33 fmt.Println(" ~/.klaus/config.json โ€” configuration")
34 }
35 return nil
36 },
37}
38
39func init() {
40 rootCmd.AddCommand(initCmd)
41}