diff options
Diffstat (limited to 'commands')
-rw-r--r-- | commands/commands.go | 1 | ||||
-rw-r--r-- | commands/hugo.go | 21 |
2 files changed, 16 insertions, 6 deletions
diff --git a/commands/commands.go b/commands/commands.go index 88939e600..17c9e15cc 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -177,6 +177,7 @@ Complete documentation is available at http://gohugo.io/.`, cc.cmd.Flags().BoolVarP(&cc.buildWatch, "watch", "w", false, "watch filesystem for changes and recreate as needed") cc.cmd.Flags().Bool("renderToMemory", false, "render to memory (only useful for benchmark testing)") + cc.cmd.Flags().Bool("minify", false, "minify any supported output format (HTML, XML etc.)") // Set bash-completion _ = cc.cmd.PersistentFlags().SetAnnotation("logFile", cobra.BashCompFilenameExt, []string{}) diff --git a/commands/hugo.go b/commands/hugo.go index 312767499..1381bf210 100644 --- a/commands/hugo.go +++ b/commands/hugo.go @@ -209,16 +209,25 @@ func initializeFlags(cmd *cobra.Command, cfg config.Provider) { "verboseLog", } + // Will set a value even if it is the default. + flagKeysForced := []string{ + "minify", + } + for _, key := range persFlagKeys { - setValueFromFlag(cmd.PersistentFlags(), key, cfg, "") + setValueFromFlag(cmd.PersistentFlags(), key, cfg, "", false) } for _, key := range flagKeys { - setValueFromFlag(cmd.Flags(), key, cfg, "") + setValueFromFlag(cmd.Flags(), key, cfg, "", false) + } + + for _, key := range flagKeysForced { + setValueFromFlag(cmd.Flags(), key, cfg, "", true) } // Set some "config aliases" - setValueFromFlag(cmd.Flags(), "destination", cfg, "publishDir") - setValueFromFlag(cmd.Flags(), "i18n-warnings", cfg, "logI18nWarnings") + setValueFromFlag(cmd.Flags(), "destination", cfg, "publishDir", false) + setValueFromFlag(cmd.Flags(), "i18n-warnings", cfg, "logI18nWarnings", false) } @@ -229,9 +238,9 @@ var deprecatedFlags = map[string]bool{ strings.ToLower("canonifyURLs"): true, } -func setValueFromFlag(flags *flag.FlagSet, key string, cfg config.Provider, targetKey string) { +func setValueFromFlag(flags *flag.FlagSet, key string, cfg config.Provider, targetKey string, force bool) { key = strings.TrimSpace(key) - if flags.Changed(key) { + if (force && flags.Lookup(key) != nil) || flags.Changed(key) { if _, deprecated := deprecatedFlags[strings.ToLower(key)]; deprecated { msg := fmt.Sprintf(`Set "%s = true" in your config.toml. If you need to set this configuration value from the command line, set it via an OS environment variable: "HUGO_%s=true hugo"`, key, strings.ToUpper(key)) |