aboutsummaryrefslogtreecommitdiffhomepage
path: root/commands/commandeer.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2023-05-22 19:00:07 +0200
committerBjørn Erik Pedersen <[email protected]>2023-05-22 20:26:02 +0200
commit85b13c105a202baf80796a5eab144d3f74a4cc42 (patch)
treefafb1ef74dc7b1e03979bb180843c5fa2b3abf1c /commands/commandeer.go
parentb6e6438f7f742cada5126aa59e856f8531dc6420 (diff)
downloadhugo-85b13c105a202baf80796a5eab144d3f74a4cc42.tar.gz
hugo-85b13c105a202baf80796a5eab144d3f74a4cc42.zip
Add --format to hugo config
Now default to TOML.
Diffstat (limited to 'commands/commandeer.go')
-rw-r--r--commands/commandeer.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/commands/commandeer.go b/commands/commandeer.go
index 8e8522b28..912a55780 100644
--- 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{})