diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-05-17 12:45:51 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-05-17 22:13:29 +0200 |
commit | 5251f015bfff40b49f92f8855834d5682f925860 (patch) | |
tree | 02c8d247b744ac1fc21a92ed46a53afce7425264 /commands | |
parent | 5d857165fed4649c3aa639a1555a15b8b1c75bab (diff) |
Re-establish all the server flags
Updates #10947
Diffstat (limited to 'commands')
-rw-r--r-- | commands/commandeer.go | 72 | ||||
-rw-r--r-- | commands/commands.go | 1 | ||||
-rw-r--r-- | commands/server.go | 9 |
3 files changed, 52 insertions, 30 deletions
diff --git a/commands/commandeer.go b/commands/commandeer.go index ed578e9bf..7e5318996 100644 --- a/commands/commandeer.go +++ b/commands/commandeer.go @@ -106,21 +106,12 @@ type rootCommand struct { commands []simplecobra.Commander // Flags - source string - baseURL string - buildWatch bool - forceSyncStatic bool - panicOnWarning bool - environment string - poll string - gc bool + source string + buildWatch bool + environment string - // Profile flags (for debugging of performance problems) - cpuprofile string - memprofile string - mutexprofile string - traceprofile string - printm bool + // Common build flags. + *buildFlags // TODO(bep) var vs string logging bool @@ -135,6 +126,21 @@ type rootCommand struct { logFile string } +type buildFlags struct { + baseURL string + gc bool + poll string + panicOnWarning bool + forceSyncStatic bool + + // Profile flags (for debugging of performance problems) + cpuprofile string + memprofile string + mutexprofile string + traceprofile string + printm bool +} + func (r *rootCommand) Build(cd *simplecobra.Commandeer, bcfg hugolib.BuildCfg, cfg config.Provider) (*hugolib.HugoSites, error) { h, err := r.Hugo(cfg) if err != nil { @@ -470,6 +476,9 @@ 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().SetAnnotation("source", cobra.BashCompSubdirsInDir, []string{}) + cmd.PersistentFlags().StringP("destination", "d", "", "filesystem path to write files to") + cmd.PersistentFlags().SetAnnotation("destination", cobra.BashCompSubdirsInDir, []string{}) + cmd.PersistentFlags().StringVarP(&r.environment, "environment", "e", "", "build environment") cmd.PersistentFlags().StringP("themesDir", "", "", "filesystem path to themes directory") cmd.PersistentFlags().StringP("ignoreVendorPaths", "", "", "ignores any _vendor for module paths matching the given Glob pattern") @@ -494,6 +503,16 @@ Complete documentation is available at https://gohugo.io/.` _ = cmd.PersistentFlags().SetAnnotation("logFile", cobra.BashCompFilenameExt, []string{}) // Configure local flags + applyLocalBuildFlags(cmd, r.buildFlags) + + // Set bash-completion. + // Each flag must first be defined before using the SetAnnotation() call. + _ = cmd.Flags().SetAnnotation("source", cobra.BashCompSubdirsInDir, []string{}) + + return nil +} + +func applyLocalBuildFlags(cmd *cobra.Command, f *buildFlags) { 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") @@ -502,27 +521,26 @@ Complete documentation is available at https://gohugo.io/.` 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().StringP("destination", "d", "", "filesystem path to write files to") 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().StringVarP(&f.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") - cmd.Flags().BoolVar(&r.panicOnWarning, "panicOnWarning", false, "panic on first WARNING log") + cmd.Flags().BoolVar(&f.gc, "gc", false, "enable to run some cleanup tasks (remove unused cache files) after the build") + cmd.Flags().StringVar(&f.poll, "poll", "", "set this to a poll interval, e.g --poll 700ms, to use a poll based approach to watch for file system changes") + cmd.Flags().BoolVar(&f.panicOnWarning, "panicOnWarning", false, "panic on first WARNING log") cmd.Flags().Bool("templateMetrics", false, "display metrics about template executions") cmd.Flags().Bool("templateMetricsHints", false, "calculate some improvement hints when combined with --templateMetrics") - cmd.Flags().BoolVar(&r.forceSyncStatic, "forceSyncStatic", false, "copy all files when static is changed.") + cmd.Flags().BoolVar(&f.forceSyncStatic, "forceSyncStatic", false, "copy all files when static is changed.") cmd.Flags().BoolP("noTimes", "", false, "don't sync modification time of files") cmd.Flags().BoolP("noChmod", "", false, "don't sync permission mode of files") cmd.Flags().BoolP("noBuildLock", "", false, "don't create .hugo_build.lock file") cmd.Flags().BoolP("printI18nWarnings", "", false, "print missing translations") cmd.Flags().BoolP("printPathWarnings", "", false, "print warnings on duplicate target paths etc.") cmd.Flags().BoolP("printUnusedTemplates", "", false, "print warnings on unused templates.") - cmd.Flags().StringVarP(&r.cpuprofile, "profile-cpu", "", "", "write cpu profile to `file`") - cmd.Flags().StringVarP(&r.memprofile, "profile-mem", "", "", "write memory profile to `file`") - cmd.Flags().BoolVarP(&r.printm, "printMemoryUsage", "", false, "print memory usage to screen at intervals") - cmd.Flags().StringVarP(&r.mutexprofile, "profile-mutex", "", "", "write Mutex profile to `file`") - cmd.Flags().StringVarP(&r.traceprofile, "trace", "", "", "write trace to `file` (not useful in general)") + cmd.Flags().StringVarP(&f.cpuprofile, "profile-cpu", "", "", "write cpu profile to `file`") + cmd.Flags().StringVarP(&f.memprofile, "profile-mem", "", "", "write memory profile to `file`") + cmd.Flags().BoolVarP(&f.printm, "printMemoryUsage", "", false, "print memory usage to screen at intervals") + cmd.Flags().StringVarP(&f.mutexprofile, "profile-mutex", "", "", "write Mutex profile to `file`") + cmd.Flags().StringVarP(&f.traceprofile, "trace", "", "", "write trace to `file` (not useful in general)") // Hide these for now. cmd.Flags().MarkHidden("profile-cpu") @@ -533,14 +551,10 @@ Complete documentation is available at https://gohugo.io/.` cmd.Flags().Bool("minify", false, "minify any supported output format (HTML, XML etc.)") - // Set bash-completion. - // Each flag must first be defined before using the SetAnnotation() call. - _ = cmd.Flags().SetAnnotation("source", cobra.BashCompSubdirsInDir, []string{}) _ = cmd.Flags().SetAnnotation("cacheDir", cobra.BashCompSubdirsInDir, []string{}) _ = cmd.Flags().SetAnnotation("destination", cobra.BashCompSubdirsInDir, []string{}) _ = cmd.Flags().SetAnnotation("theme", cobra.BashCompSubdirsInDir, []string{"themes"}) - return nil } func (r *rootCommand) timeTrack(start time.Time, name string) { diff --git a/commands/commands.go b/commands/commands.go index 9d707b841..f90b09e0c 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -20,6 +20,7 @@ import ( // newExec wires up all of Hugo's CLI. func newExec() (*simplecobra.Exec, error) { rootCmd := &rootCommand{ + buildFlags: &buildFlags{}, commands: []simplecobra.Commander{ newVersionCmd(), newEnvCommand(), diff --git a/commands/server.go b/commands/server.go index 81a5120ef..5c2fd7704 100644 --- a/commands/server.go +++ b/commands/server.go @@ -99,7 +99,8 @@ func newHugoBuilder(r *rootCommand, s *serverCommand, onConfigLoaded ...func(rel func newServerCommand() *serverCommand { var c *serverCommand c = &serverCommand{ - quit: make(chan bool), + buildFlags: &buildFlags{}, + quit: make(chan bool), } return c } @@ -408,6 +409,9 @@ type serverCommand struct { // Flags. + // Common build flags. + *buildFlags + renderToDisk bool renderStaticToDisk bool navigateToChanged bool @@ -499,6 +503,9 @@ of a second, you will be able to save and see your changes nearly instantly.` cmd.Flags().String("memstats", "", "log memory usage to this file") cmd.Flags().String("meminterval", "100ms", "interval to poll memory usage (requires --memstats), valid time units are \"ns\", \"us\" (or \"µs\"), \"ms\", \"s\", \"m\", \"h\".") + + applyLocalBuildFlags(cmd, c.buildFlags) + return nil } |