URI: 
       commands: Move the --format flag to only the commands that support it - hugo - [fork] hugo port for 9front
  HTML git clone git@git.drkhsh.at/hugo.git
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
   DIR README
   DIR LICENSE
       ---
   DIR commit f86b5f70a60fc3793bc826f2ccd8dcdd62e26b51
   DIR parent 3297b395d8d5fadb45b9055e55458967fb9f4a76
  HTML Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
       Date:   Sat, 27 May 2023 15:04:36 +0200
       
       commands: Move the --format flag to only the commands that support it
       
       Fixes #11022
       
       Diffstat:
         M commands/commandeer.go              |      10 ----------
         M commands/config.go                  |       9 ++++++++-
         M commands/new.go                     |       7 +++++--
       
       3 files changed, 13 insertions(+), 13 deletions(-)
       ---
   DIR diff --git a/commands/commandeer.go b/commands/commandeer.go
       @@ -108,9 +108,6 @@ type rootCommand struct {
                buildWatch  bool
                environment string
        
       -        // File format to read or write (TOML, YAML, JSON).
       -        format string
       -
                // Common build flags.
                baseURL              string
                gc                   bool
       @@ -408,12 +405,6 @@ func (r *rootCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
                if err != nil {
                        return err
                }
       -        switch r.format {
       -        case "json", "toml", "yaml":
       -                // OK
       -        default:
       -                return fmt.Errorf("unsupported format %q; must be one of json, toml or yaml", r.format)
       -        }
        
                loggers.PanicOnWarning.Store(r.panicOnWarning)
                r.commonConfigs = lazycache.New[int32, *commonConfig](lazycache.Options{MaxEntries: 5})
       @@ -485,7 +476,6 @@ Complete documentation is available at https://gohugo.io/.`
        
                // Configure persistent flags
                cmd.PersistentFlags().StringVarP(&r.source, "source", "s", "", "filesystem path to read files relative from")
       -        cmd.PersistentFlags().StringVar(&r.format, "format", "toml", "preferred file format (toml, yaml or json)")
                cmd.PersistentFlags().SetAnnotation("source", cobra.BashCompSubdirsInDir, []string{})
                cmd.PersistentFlags().StringP("destination", "d", "", "filesystem path to write files to")
                cmd.PersistentFlags().SetAnnotation("destination", cobra.BashCompSubdirsInDir, []string{})
   DIR diff --git a/commands/config.go b/commands/config.go
       @@ -17,6 +17,7 @@ import (
                "bytes"
                "context"
                "encoding/json"
       +        "fmt"
                "os"
                "strings"
                "time"
       @@ -40,6 +41,8 @@ func newConfigCommand() *configCommand {
        type configCommand struct {
                r *rootCommand
        
       +        format string
       +
                commands []simplecobra.Commander
        }
        
       @@ -67,7 +70,7 @@ func (c *configCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, arg
                        return err
                }
        
       -        format := strings.ToLower(c.r.format)
       +        format := strings.ToLower(c.format)
        
                switch format {
                case "json":
       @@ -83,6 +86,8 @@ func (c *configCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, arg
                                return parser.InterfaceToConfig(m, metadecoders.YAML, os.Stdout)
                        case "toml":
                                return parser.InterfaceToConfig(m, metadecoders.TOML, os.Stdout)
       +                default:
       +                        return fmt.Errorf("unsupported format: %q", format)
                        }
                }
        
       @@ -93,6 +98,8 @@ func (c *configCommand) Init(cd *simplecobra.Commandeer) error {
                cmd := cd.CobraCommand
                cmd.Short = "Print the site configuration"
                cmd.Long = `Print the site configuration, both default and custom settings.`
       +        cmd.Flags().StringVar(&c.format, "format", "toml", "preferred file format (toml, yaml or json)")
       +
                return nil
        }
        
   DIR diff --git a/commands/new.go b/commands/new.go
       @@ -36,6 +36,7 @@ func newNewCommand() *newCommand {
                var (
                        force       bool
                        contentType string
       +                format      string
                )
        
                var c *newCommand
       @@ -67,6 +68,8 @@ func newNewCommand() *newCommand {
                                                cmd.Flags().StringVarP(&contentType, "kind", "k", "", "content type to create")
                                                cmd.Flags().String("editor", "", "edit new content with this editor, if provided")
                                                cmd.Flags().BoolVarP(&force, "force", "f", false, "overwrite file if it already exists")
       +                                        cmd.Flags().StringVar(&format, "format", "toml", "preferred file format (toml, yaml or json)")
       +
                                        },
                                },
                                &simpleCommand{
       @@ -118,7 +121,7 @@ Use ` + "`hugo new [contentPath]`" + ` to create new content.`,
                                                                return errors.New(createpath + " already exists and is not empty. See --force.")
        
                                                        case !isEmpty && force:
       -                                                        all := append(dirs, filepath.Join(createpath, "hugo."+r.format))
       +                                                        all := append(dirs, filepath.Join(createpath, "hugo."+format))
                                                                for _, path := range all {
                                                                        if exists, _ := helpers.Exists(path, sourceFs); exists {
                                                                                return errors.New(path + " already exists")
       @@ -133,7 +136,7 @@ Use ` + "`hugo new [contentPath]`" + ` to create new content.`,
                                                        }
                                                }
        
       -                                        c.newSiteCreateConfig(sourceFs, createpath, r.format)
       +                                        c.newSiteCreateConfig(sourceFs, createpath, format)
        
                                                // Create a default archetype file.
                                                helpers.SafeWriteToDisk(filepath.Join(archeTypePath, "default.md"),