URI: 
       Add --format to hugo config - 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 85b13c105a202baf80796a5eab144d3f74a4cc42
   DIR parent b6e6438f7f742cada5126aa59e856f8531dc6420
  HTML Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
       Date:   Mon, 22 May 2023 19:00:07 +0200
       
       Add --format to hugo config
       
       Now default to TOML.
       
       Diffstat:
         M commands/commandeer.go              |      10 ++++++++++
         M commands/config.go                  |      26 ++++++++++++++++++++++++--
         M commands/new.go                     |      10 ++++------
         M testscripts/commands/config.txt     |       2 ++
       
       4 files changed, 40 insertions(+), 8 deletions(-)
       ---
   DIR diff --git a/commands/commandeer.go b/commands/commandeer.go
       @@ -108,6 +108,9 @@ 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
       @@ -405,6 +408,12 @@ 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})
       @@ -476,6 +485,7 @@ 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
       @@ -14,9 +14,11 @@
        package commands
        
        import (
       +        "bytes"
                "context"
                "encoding/json"
                "os"
       +        "strings"
                "time"
        
                "github.com/bep/simplecobra"
       @@ -56,14 +58,34 @@ func (c *configCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, arg
                }
                config := conf.configs.Base
        
       -        // Print it as JSON.
       -        dec := json.NewEncoder(os.Stdout)
       +        var buf bytes.Buffer
       +        dec := json.NewEncoder(&buf)
                dec.SetIndent("", "  ")
                dec.SetEscapeHTML(false)
        
                if err := dec.Encode(parser.ReplacingJSONMarshaller{Value: config, KeysToLower: true, OmitEmpty: true}); err != nil {
                        return err
                }
       +
       +        format := strings.ToLower(c.r.format)
       +
       +        switch format {
       +        case "json":
       +                os.Stdout.Write(buf.Bytes())
       +        default:
       +                // Decode the JSON to a map[string]interface{} and then unmarshal it again to the correct format.
       +                var m map[string]interface{}
       +                if err := json.Unmarshal(buf.Bytes(), &m); err != nil {
       +                        return err
       +                }
       +                switch format {
       +                case "yaml":
       +                        return parser.InterfaceToConfig(m, metadecoders.YAML, os.Stdout)
       +                case "toml":
       +                        return parser.InterfaceToConfig(m, metadecoders.TOML, os.Stdout)
       +                }
       +        }
       +
                return nil
        }
        
   DIR diff --git a/commands/new.go b/commands/new.go
       @@ -34,9 +34,8 @@ import (
        
        func newNewCommand() *newCommand {
                var (
       -                configFormat string
       -                force        bool
       -                contentType  string
       +                force       bool
       +                contentType string
                )
        
                var c *newCommand
       @@ -119,7 +118,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."+configFormat))
       +                                                        all := append(dirs, filepath.Join(createpath, "hugo."+r.format))
                                                                for _, path := range all {
                                                                        if exists, _ := helpers.Exists(path, sourceFs); exists {
                                                                                return errors.New(path + " already exists")
       @@ -134,7 +133,7 @@ Use ` + "`hugo new [contentPath]`" + ` to create new content.`,
                                                        }
                                                }
        
       -                                        c.newSiteCreateConfig(sourceFs, createpath, configFormat)
       +                                        c.newSiteCreateConfig(sourceFs, createpath, r.format)
        
                                                // Create a default archetype file.
                                                helpers.SafeWriteToDisk(filepath.Join(archeTypePath, "default.md"),
       @@ -146,7 +145,6 @@ Use ` + "`hugo new [contentPath]`" + ` to create new content.`,
                                                return nil
                                        },
                                        withc: func(cmd *cobra.Command) {
       -                                        cmd.Flags().StringVarP(&configFormat, "format", "f", "toml", "config file format")
                                                cmd.Flags().BoolVar(&force, "force", false, "init inside non-empty directory")
                                        },
                                },
   DIR diff --git a/testscripts/commands/config.txt b/testscripts/commands/config.txt
       @@ -5,6 +5,8 @@ stdout 'Print the site configuration'
        
        
        hugo config
       +stdout 'baseurl = .https://example.com/'
       +hugo config --format json
        stdout '\"baseurl\": \"https://example.com/\",'
        
        hugo config mounts -h