| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | _ "embed" |
| 5 | "fmt" |
| 6 | "os" |
| 7 | |
| 8 | "github.com/spf13/cobra" |
| 9 | ) |
| 10 | |
| 11 | //go:embed curator.default.yaml |
| 12 | var defaultConfig string |
| 13 | |
| 14 | func initConfigCmd() *cobra.Command { |
| 15 | var out string |
| 16 | |
| 17 | cmd := &cobra.Command{ |
| 18 | Use: "init-config", |
| 19 | Short: "Generate a default configuration file", |
| 20 | RunE: func(cmd *cobra.Command, args []string) error { |
| 21 | if out == "" { |
| 22 | fmt.Print(defaultConfig) |
| 23 | return nil |
| 24 | } |
| 25 | |
| 26 | if err := os.WriteFile(out, []byte(defaultConfig), 0o644); err != nil { |
| 27 | return fmt.Errorf("write config: %w", err) |
| 28 | } |
| 29 | fmt.Fprintf(os.Stderr, "config written to %s\n", out) |
| 30 | return nil |
| 31 | }, |
| 32 | } |
| 33 | |
| 34 | cmd.Flags().StringVarP(&out, "out", "o", "", "write config to file (default: stdout)") |
| 35 | |
| 36 | return cmd |
| 37 | } |
| 38 | |