gunk-dev/the-valley

init.go

source6a6791929c36main's published tip history
1.1 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).`,
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
43func init() {
44 rootCmd.AddCommand(initCmd)
45}