MCPcopy Create free account
hub / github.com/SamNet-dev/snix / newInitCmd

Function newInitCmd

cmd/snix/commands.go:125–147  ·  view source on GitHub ↗

-- snix init -------------------------------------------------------------

(g *globalFlags)

Source from the content-addressed store, hash-verified

123// -- snix init -------------------------------------------------------------
124
125func newInitCmd(g *globalFlags) *cobra.Command {
126 var wizard, force bool
127 c := &cobra.Command{
128 Use: "init",
129 Short: "Create a starter config, or run the interactive wizard",
130 RunE: func(cmd *cobra.Command, _ []string) error {
131 if err := os.MkdirAll(filepath.Dir(g.configPath), 0o755); err != nil {
132 return err
133 }
134 if _, err := os.Stat(g.configPath); err == nil && !force {
135 return fmt.Errorf("config already exists at %s (pass --force to overwrite)", g.configPath)
136 }
137 if wizard {
138 in := bufio.NewReader(cmd.InOrStdin())
139 return runWizard(cmd.OutOrStdout(), in, g.configPath)
140 }
141 return os.WriteFile(g.configPath, []byte(sampleConfig), 0o644)
142 },
143 }
144 c.Flags().BoolVar(&wizard, "wizard", false, "interactive first-run wizard (recommended for new users)")
145 c.Flags().BoolVar(&force, "force", false, "overwrite any existing config")
146 return c
147}
148
149const sampleConfig = `version: 1
150active: default

Callers 1

newRootCmdFunction · 0.85

Calls 1

runWizardFunction · 0.85

Tested by

no test coverage detected