diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-07-07 18:06:48 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-07-07 18:06:48 +0200 |
commit | b581bbd8563a7c7ee95f9dcf76850370df4673d2 (patch) | |
tree | 8db5a51dd3fb9386070f2f334bfbcb61f20a8bf2 /commands | |
parent | 223073c6fdf1258de41782f96444ac81f32e9235 (diff) |
Make config flag global
Fixes #2261
Diffstat (limited to 'commands')
-rw-r--r-- | commands/hugo.go | 11 | ||||
-rw-r--r-- | commands/list_config.go | 6 |
2 files changed, 7 insertions, 10 deletions
diff --git a/commands/hugo.go b/commands/hugo.go index d979c3c62..fa0467288 100644 --- a/commands/hugo.go +++ b/commands/hugo.go @@ -198,17 +198,15 @@ func AddCommands() { // initHugoBuilderFlags initializes all common flags, typically used by the // core build commands, namely hugo itself, server, check and benchmark. func initHugoBuilderFlags(cmd *cobra.Command) { - initCoreCommonFlags(cmd) initHugoBuildCommonFlags(cmd) } -// initCoreCommonFlags initializes common flags used by Hugo core commands. -func initCoreCommonFlags(cmd *cobra.Command) { - cmd.Flags().StringVar(&cfgFile, "config", "", "config file (default is path/config.yaml|json|toml)") +func initRootPersistentFlags() { + HugoCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is path/config.yaml|json|toml)") // Set bash-completion validConfigFilenames := []string{"json", "js", "yaml", "yml", "toml", "tml"} - cmd.Flags().SetAnnotation("config", cobra.BashCompFilenameExt, validConfigFilenames) + HugoCmd.PersistentFlags().SetAnnotation("config", cobra.BashCompFilenameExt, validConfigFilenames) } // initHugoBuildCommonFlags initialize common flags related to the Hugo build. @@ -257,6 +255,7 @@ func init() { HugoCmd.PersistentFlags().StringVar(&logFile, "logFile", "", "Log File path (if set, logging enabled automatically)") HugoCmd.PersistentFlags().BoolVar(&verboseLog, "verboseLog", false, "verbose logging") + initRootPersistentFlags() initHugoBuilderFlags(HugoCmd) initBenchmarkBuildingFlags(HugoCmd) @@ -319,8 +318,6 @@ func loadDefaultSettings() { } // InitializeConfig initializes a config file with sensible default configuration flags. -// A Hugo command that calls initCoreCommonFlags() can pass itself -// as an argument to have its command-line flags processed here. func InitializeConfig(subCmdVs ...*cobra.Command) error { viper.AutomaticEnv() viper.SetEnvPrefix("hugo") diff --git a/commands/list_config.go b/commands/list_config.go index 1b90f11ce..d53cc5884 100644 --- a/commands/list_config.go +++ b/commands/list_config.go @@ -15,10 +15,11 @@ package commands import ( "fmt" - "github.com/spf13/cobra" - "github.com/spf13/viper" "reflect" "sort" + + "github.com/spf13/cobra" + "github.com/spf13/viper" ) var configCmd = &cobra.Command{ @@ -28,7 +29,6 @@ var configCmd = &cobra.Command{ } func init() { - initCoreCommonFlags(configCmd) configCmd.RunE = config } |