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