aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2023-05-28 10:44:40 +0200
committerBjørn Erik Pedersen <[email protected]>2023-05-28 12:55:44 +0200
commit43f1282e734f5a27f99ff6efb29190a234b3447a (patch)
tree0e58d06118a6d13c93fed23baa13563fd3da2395
parente96cdfe9664cb38c3e16cc00cc630cf6f258d547 (diff)
downloadhugo-43f1282e734f5a27f99ff6efb29190a234b3447a.tar.gz
hugo-43f1282e734f5a27f99ff6efb29190a234b3447a.zip
commands: Reinstate some of the removed build flags (e.g. --theme) to new and mod
Fixes #11018
-rw-r--r--commands/commandeer.go33
-rw-r--r--commands/convert.go6
-rw-r--r--commands/deploy.go2
-rw-r--r--commands/deploy_off.go2
-rw-r--r--commands/gen.go8
-rw-r--r--commands/import.go2
-rw-r--r--commands/mod.go23
-rw-r--r--commands/new.go5
-rw-r--r--commands/release.go2
-rw-r--r--commands/server.go2
-rw-r--r--commands/xcommand_template.go2
-rw-r--r--testscripts/commands/mod__themesdir.txt7
-rw-r--r--testscripts/commands/new.txt23
13 files changed, 84 insertions, 33 deletions
diff --git a/commands/commandeer.go b/commands/commandeer.go
index 7b0c41652..23781f57c 100644
--- a/commands/commandeer.go
+++ b/commands/commandeer.go
@@ -504,7 +504,7 @@ Complete documentation is available at https://gohugo.io/.`
_ = cmd.PersistentFlags().SetAnnotation("logFile", cobra.BashCompFilenameExt, []string{})
// Configure local flags
- applyLocalBuildFlags(cmd, r)
+ applyLocalFlagsBuild(cmd, r)
// Set bash-completion.
// Each flag must first be defined before using the SetAnnotation() call.
@@ -513,17 +513,26 @@ Complete documentation is available at https://gohugo.io/.`
return nil
}
-func applyLocalBuildFlags(cmd *cobra.Command, r *rootCommand) {
+// A sub set of the complete build flags. These flags are used by new and mod.
+func applyLocalFlagsBuildConfig(cmd *cobra.Command, r *rootCommand) {
+ cmd.Flags().StringSliceP("theme", "t", []string{}, "themes to use (located in /themes/THEMENAME/)")
+ cmd.Flags().StringVarP(&r.baseURL, "baseURL", "b", "", "hostname (and path) to the root, e.g. https://spf13.com/")
+ cmd.Flags().StringP("cacheDir", "", "", "filesystem path to cache directory. Defaults: $TMPDIR/hugo_cache/")
+ _ = cmd.Flags().SetAnnotation("cacheDir", cobra.BashCompSubdirsInDir, []string{})
+ cmd.Flags().StringP("contentDir", "c", "", "filesystem path to content directory")
+ cmd.Flags().StringP("layoutDir", "l", "", "filesystem path to layout directory")
+ _ = cmd.Flags().SetAnnotation("theme", cobra.BashCompSubdirsInDir, []string{"themes"})
+
+}
+
+// Flags needed to do a build (used by hugo and hugo server commands)
+func applyLocalFlagsBuild(cmd *cobra.Command, r *rootCommand) {
+ applyLocalFlagsBuildConfig(cmd, r)
cmd.Flags().Bool("cleanDestinationDir", false, "remove files from destination not found in static directories")
cmd.Flags().BoolP("buildDrafts", "D", false, "include content marked as draft")
cmd.Flags().BoolP("buildFuture", "F", false, "include content with publishdate in the future")
cmd.Flags().BoolP("buildExpired", "E", false, "include expired content")
- cmd.Flags().StringP("contentDir", "c", "", "filesystem path to content directory")
- cmd.Flags().StringP("layoutDir", "l", "", "filesystem path to layout directory")
- cmd.Flags().StringP("cacheDir", "", "", "filesystem path to cache directory. Defaults: $TMPDIR/hugo_cache/")
cmd.Flags().BoolP("ignoreCache", "", false, "ignores the cache directory")
- cmd.Flags().StringSliceP("theme", "t", []string{}, "themes to use (located in /themes/THEMENAME/)")
- cmd.Flags().StringVarP(&r.baseURL, "baseURL", "b", "", "hostname (and path) to the root, e.g. https://spf13.com/")
cmd.Flags().Bool("enableGitInfo", false, "add Git revision, date, author, and CODEOWNERS info to the pages")
cmd.Flags().BoolVar(&r.gc, "gc", false, "enable to run some cleanup tasks (remove unused cache files) after the build")
cmd.Flags().StringVar(&r.poll, "poll", "", "set this to a poll interval, e.g --poll 700ms, to use a poll based approach to watch for file system changes")
@@ -549,12 +558,8 @@ func applyLocalBuildFlags(cmd *cobra.Command, r *rootCommand) {
cmd.Flags().MarkHidden("profile-mutex")
cmd.Flags().StringSlice("disableKinds", []string{}, "disable different kind of pages (home, RSS etc.)")
-
cmd.Flags().Bool("minify", false, "minify any supported output format (HTML, XML etc.)")
-
- _ = cmd.Flags().SetAnnotation("cacheDir", cobra.BashCompSubdirsInDir, []string{})
_ = cmd.Flags().SetAnnotation("destination", cobra.BashCompSubdirsInDir, []string{})
- _ = cmd.Flags().SetAnnotation("theme", cobra.BashCompSubdirsInDir, []string{"themes"})
}
@@ -569,7 +574,7 @@ type simpleCommand struct {
short string
long string
run func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *rootCommand, args []string) error
- withc func(cmd *cobra.Command)
+ withc func(cmd *cobra.Command, r *rootCommand)
initc func(cd *simplecobra.Commandeer) error
commands []simplecobra.Commander
@@ -593,6 +598,7 @@ func (c *simpleCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, arg
}
func (c *simpleCommand) Init(cd *simplecobra.Commandeer) error {
+ c.rootCmd = cd.Root.Command.(*rootCommand)
cmd := cd.CobraCommand
cmd.Short = c.short
cmd.Long = c.long
@@ -600,13 +606,12 @@ func (c *simpleCommand) Init(cd *simplecobra.Commandeer) error {
cmd.Use = c.use
}
if c.withc != nil {
- c.withc(cmd)
+ c.withc(cmd, c.rootCmd)
}
return nil
}
func (c *simpleCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
- c.rootCmd = cd.Root.Command.(*rootCommand)
if c.initc != nil {
return c.initc(cd)
}
diff --git a/commands/convert.go b/commands/convert.go
index e5c367913..765fb5f54 100644
--- a/commands/convert.go
+++ b/commands/convert.go
@@ -45,7 +45,7 @@ to use JSON for the front matter.`,
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
return c.convertContents(metadecoders.JSON)
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
},
},
&simpleCommand{
@@ -56,7 +56,7 @@ to use TOML for the front matter.`,
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
return c.convertContents(metadecoders.TOML)
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
},
},
&simpleCommand{
@@ -67,7 +67,7 @@ to use YAML for the front matter.`,
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
return c.convertContents(metadecoders.YAML)
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
},
},
},
diff --git a/commands/deploy.go b/commands/deploy.go
index 0340ea3c4..8dae4bd88 100644
--- a/commands/deploy.go
+++ b/commands/deploy.go
@@ -58,7 +58,7 @@ documentation.
}
return deployer.Deploy(ctx)
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
cmd.Flags().String("target", "", "target deployment from deployments section in config file; defaults to the first one")
cmd.Flags().Bool("confirm", false, "ask for confirmation before making changes to the target")
cmd.Flags().Bool("dryRun", false, "dry run")
diff --git a/commands/deploy_off.go b/commands/deploy_off.go
index 5e9b91f16..b238d6cf7 100644
--- a/commands/deploy_off.go
+++ b/commands/deploy_off.go
@@ -41,7 +41,7 @@ func newDeployCommand() simplecobra.Commander {
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
return nil
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
cmd.Hidden = true
},
}
diff --git a/commands/gen.go b/commands/gen.go
index 1f8109e01..c5eab894a 100644
--- a/commands/gen.go
+++ b/commands/gen.go
@@ -70,7 +70,7 @@ See https://xyproto.github.io/splash/docs/all.html for a preview of the availabl
formatter.WriteCSS(os.Stdout, style)
return nil
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
cmd.PersistentFlags().StringVar(&style, "style", "friendly", "highlighter style (see https://xyproto.github.io/splash/docs/)")
cmd.PersistentFlags().StringVar(&highlightStyle, "highlightStyle", "bg:#ffffcc", "style used for highlighting lines (see https://github.com/alecthomas/chroma)")
cmd.PersistentFlags().StringVar(&linesStyle, "linesStyle", "", "style used for line numbers (see https://github.com/alecthomas/chroma)")
@@ -110,7 +110,7 @@ See https://xyproto.github.io/splash/docs/all.html for a preview of the availabl
return nil
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
cmd.PersistentFlags().StringVar(&genmandir, "dir", "man/", "the directory to write the man pages.")
// For bash-completion
cmd.PersistentFlags().SetAnnotation("dir", cobra.BashCompSubdirsInDir, []string{})
@@ -167,7 +167,7 @@ url: %s
return nil
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
cmd.PersistentFlags().StringVar(&gendocdir, "dir", "/tmp/hugodoc/", "the directory to write the doc.")
// For bash-completion
cmd.PersistentFlags().SetAnnotation("dir", cobra.BashCompSubdirsInDir, []string{})
@@ -204,7 +204,7 @@ url: %s
r.Println("Done!")
return nil
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
cmd.Hidden = true
cmd.PersistentFlags().StringVarP(&docsHelperTarget, "dir", "", "docs/data", "data dir")
},
diff --git a/commands/import.go b/commands/import.go
index 258323a3a..30ada15f8 100644
--- a/commands/import.go
+++ b/commands/import.go
@@ -59,7 +59,7 @@ Import from Jekyll requires two paths, e.g. ` + "`hugo import jekyll jekyll_root
}
return c.importFromJekyll(args)
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
cmd.Flags().BoolVar(&c.force, "force", false, "allow import into non-empty target directory")
},
},
diff --git a/commands/mod.go b/commands/mod.go
index 1af1f7431..36d4a5596 100644
--- a/commands/mod.go
+++ b/commands/mod.go
@@ -61,6 +61,9 @@ This command is marked as 'Experimental'. We think it's a great idea, so it's no
removed from Hugo, but we need to test this out in "real life" to get a feel of it,
so this may/will change in future versions of Hugo.
`,
+ withc: func(cmd *cobra.Command, r *rootCommand) {
+ applyLocalFlagsBuildConfig(cmd, r)
+ },
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
h, err := r.Hugo(flagsToCfg(cd, nil))
if err != nil {
@@ -85,6 +88,9 @@ so this may/will change in future versions of Hugo.
Note that Hugo Modules supports multi-module projects, so you can initialize a Hugo Module
inside a subfolder on GitHub, as one example.
`,
+ withc: func(cmd *cobra.Command, r *rootCommand) {
+ applyLocalFlagsBuildConfig(cmd, r)
+ },
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
h, err := r.Hugo(flagsToCfg(cd, nil))
if err != nil {
@@ -101,7 +107,8 @@ so this may/will change in future versions of Hugo.
name: "verify",
short: "Verify dependencies.",
long: `Verify checks that the dependencies of the current module, which are stored in a local downloaded source cache, have not been modified since being downloaded.`,
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
+ applyLocalFlagsBuildConfig(cmd, r)
cmd.Flags().BoolVarP(&clean, "clean", "", false, "delete module cache for dependencies that fail verification")
},
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
@@ -119,7 +126,8 @@ so this may/will change in future versions of Hugo.
long: `Print a module dependency graph with information about module status (disabled, vendored).
Note that for vendored modules, that is the version listed and not the one from go.mod.
`,
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
+ applyLocalFlagsBuildConfig(cmd, r)
cmd.Flags().BoolVarP(&clean, "clean", "", false, "delete module cache for dependencies that fail verification")
},
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
@@ -135,7 +143,8 @@ Note that for vendored modules, that is the version listed and not the one from
name: "clean",
short: "Delete the Hugo Module cache for the current project.",
long: `Delete the Hugo Module cache for the current project.`,
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
+ applyLocalFlagsBuildConfig(cmd, r)
cmd.Flags().StringVarP(&pattern, "pattern", "", "", `pattern matching module paths to clean (all if not set), e.g. "**hugo*"`)
cmd.Flags().BoolVarP(&all, "all", "", false, "clean entire module cache")
},
@@ -157,6 +166,9 @@ Note that for vendored modules, that is the version listed and not the one from
&simpleCommand{
name: "tidy",
short: "Remove unused entries in go.mod and go.sum.",
+ withc: func(cmd *cobra.Command, r *rootCommand) {
+ applyLocalFlagsBuildConfig(cmd, r)
+ },
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
h, err := r.Hugo(flagsToCfg(cd, nil))
if err != nil {
@@ -171,6 +183,9 @@ Note that for vendored modules, that is the version listed and not the one from
long: `Vendor all module dependencies into the _vendor directory.
If a module is vendored, that is where Hugo will look for it's dependencies.
`,
+ withc: func(cmd *cobra.Command, r *rootCommand) {
+ applyLocalFlagsBuildConfig(cmd, r)
+ },
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
h, err := r.Hugo(flagsToCfg(cd, nil))
if err != nil {
@@ -203,7 +218,7 @@ Install the latest versions of all module dependencies:
Run "go help get" for more information. All flags available for "go get" is also relevant here.
` + commonUsageMod,
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
cmd.DisableFlagParsing = true
},
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
diff --git a/commands/new.go b/commands/new.go
index fc9a0bd8c..6760bf719 100644
--- a/commands/new.go
+++ b/commands/new.go
@@ -64,11 +64,12 @@ func newNewCommand() *newCommand {
}
return create.NewContent(h, contentType, args[0], force)
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
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)")
+ applyLocalFlagsBuildConfig(cmd, r)
},
},
@@ -147,7 +148,7 @@ Use ` + "`hugo new [contentPath]`" + ` to create new content.`,
return nil
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
cmd.Flags().BoolVarP(&force, "force", "f", false, "init inside non-empty directory")
},
},
diff --git a/commands/release.go b/commands/release.go
index fe3c5efb6..54cf936e8 100644
--- a/commands/release.go
+++ b/commands/release.go
@@ -42,7 +42,7 @@ func newReleaseCommand() simplecobra.Commander {
return rel.Run()
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
cmd.Hidden = true
cmd.PersistentFlags().BoolVarP(&skipPush, "skip-push", "", false, "skip pushing to remote")
cmd.PersistentFlags().BoolVarP(&try, "try", "", false, "no changes")
diff --git a/commands/server.go b/commands/server.go
index 4669cf0b4..c878cac2f 100644
--- a/commands/server.go
+++ b/commands/server.go
@@ -509,7 +509,7 @@ of a second, you will be able to save and see your changes nearly instantly.`
cmd.Flags().String("meminterval", "100ms", "interval to poll memory usage (requires --memstats), valid time units are \"ns\", \"us\" (or \"µs\"), \"ms\", \"s\", \"m\", \"h\".")
r := cd.Root.Command.(*rootCommand)
- applyLocalBuildFlags(cmd, r)
+ applyLocalFlagsBuild(cmd, r)
return nil
}
diff --git a/commands/xcommand_template.go b/commands/xcommand_template.go
index 7ceeffb19..eeb9409a0 100644
--- a/commands/xcommand_template.go
+++ b/commands/xcommand_template.go
@@ -28,7 +28,7 @@ func newSimpleTemplateCommand() simplecobra.Commander {
return nil
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
},
}
diff --git a/testscripts/commands/mod__themesdir.txt b/testscripts/commands/mod__themesdir.txt
new file mode 100644
index 000000000..ec76d0c76
--- /dev/null
+++ b/testscripts/commands/mod__themesdir.txt
@@ -0,0 +1,7 @@
+hugo --theme mytheme mod graph
+stdout 'project mytheme'
+
+-- hugo.toml --
+title = "Hugo Module"
+-- themes/mytheme/hugo.toml --
+title = "My Theme"
diff --git a/testscripts/commands/new.txt b/testscripts/commands/new.txt
index aeebba66d..aad0d80f6 100644
--- a/testscripts/commands/new.txt
+++ b/testscripts/commands/new.txt
@@ -25,3 +25,26 @@ stdout 'Create a new content file.'
hugo new posts/my-first-post.md
checkfile content/posts/my-first-post.md
+cd ..
+cd myexistingsite
+hugo new post/foo.md -t mytheme
+grep 'Dummy content' content/post/foo.md
+
+-- myexistingsite/hugo.toml --
+theme = "mytheme"
+-- myexistingsite/content/p1.md --
+---
+title: "P1"
+---
+-- myexistingsite/themes/mytheme/hugo.toml --
+-- myexistingsite/themes/mytheme/archetypes/post.md --
+---
+title: "{{ replace .Name "-" " " | title }}"
+date: {{ .Date }}
+draft: true
+---
+
+Dummy content.
+
+
+