From f86b5f70a60fc3793bc826f2ccd8dcdd62e26b51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sat, 27 May 2023 15:04:36 +0200 Subject: commands: Move the --format flag to only the commands that support it Fixes #11022 --- commands/new.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'commands/new.go') diff --git a/commands/new.go b/commands/new.go index 8a2b02293..d021be027 100644 --- 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"), -- cgit v1.2.3