gunk-dev/the-valley

init.go

source4cbb5ec9c5dbmain's published tip history
1.3 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 default config.json and prompt.md template.
15
16If run inside a git repository, writes them in the repo's .klaus/ (or over the
17ones in .valley/flow/, where a repo keeps them there).
18If run outside a git repository, writes the host config, ~/.klaus/config.json
19(or ~/.valley/flow/config.json, where the host keeps it).
20Under the bridge naming generation, a file that doesn't exist yet goes under
21.valley/flow/ (~/.valley/flow/ for the host config), and the config's
22worktree_base is the bridge default.`,
23 RunE: func(cmd *cobra.Command, args []string) error {
24 root, _ := git.RepoRoot()
25
26 if root != "" {
27 configPath, promptPath, err := config.Init(root)
28 if err != nil {
29 return err
30 }
31 fmt.Println("Initialized flow config:")
32 fmt.Printf(" %s โ€” configuration\n", configPath)
33 fmt.Printf(" %s โ€” system prompt template\n", promptPath)
34 } else {
35 path, err := config.InitGlobal()
36 if err != nil {
37 return err
38 }
39 fmt.Println("Initialized global flow config:")
40 fmt.Printf(" %s โ€” configuration\n", path)
41 }
42 return nil
43 },
44}
45
46func init() {
47 rootCmd.AddCommand(initCmd)
48}