Move the example generation to separate flag

This commit is contained in:
2025-11-02 20:04:39 +01:00
parent 60ba3ad417
commit 91ad9006fa

View File

@@ -12,8 +12,8 @@ import (
"cook/processor"
"cook/utils"
"github.com/spf13/cobra"
logger "git.site.quack-lab.dev/dave/cylogger"
"github.com/spf13/cobra"
)
//go:embed example_cook.toml
@@ -54,12 +54,16 @@ Features:
- Parallel file processing
- Command filtering and organization`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
CreateExampleConfig()
logger.InitFlag()
mainLogger.Info("Initializing with log level: %s", logger.GetLevel().String())
mainLogger.Trace("Full argv: %v", os.Args)
},
Run: func(cmd *cobra.Command, args []string) {
exampleFlag, _ := cmd.Flags().GetBool("example")
if exampleFlag {
CreateExampleConfig()
return
}
if len(args) == 0 {
cmd.Usage()
return
@@ -76,6 +80,7 @@ Features:
rootCmd.Flags().StringP("filter", "f", "", "Filter commands before running them")
rootCmd.Flags().Bool("json", false, "Enable JSON mode for processing JSON files")
rootCmd.Flags().BoolP("conv", "c", false, "Convert YAML files to TOML format")
rootCmd.Flags().BoolP("example", "e", false, "Generate example_cook.toml and exit")
// Set up examples in the help text
rootCmd.SetUsageTemplate(`Usage:{{if .Runnable}}