-- snix init -------------------------------------------------------------
(g *globalFlags)
| 123 | // -- snix init ------------------------------------------------------------- |
| 124 | |
| 125 | func 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 | |
| 149 | const sampleConfig = `version: 1 |
| 150 | active: default |
no test coverage detected