cmd: Replace flagChanged with pflag.FlagSet.Changed

This commit is contained in:
Albert Nigmatzianov 2017-05-24 10:51:48 +02:00
parent 0a40cb43ea
commit 421a46947a
3 changed files with 8 additions and 16 deletions

View file

@ -467,15 +467,15 @@ func (c *commandeer) initializeFlags(cmd *cobra.Command) {
}
// Remove these in Hugo 0.23.
if flagChanged(cmd.Flags(), "disable404") {
if cmd.Flags().Changed("disable404") {
helpers.Deprecated("command line", "--disable404", "Use --disableKinds=404", false)
}
if flagChanged(cmd.Flags(), "disableRSS") {
if cmd.Flags().Changed("disableRSS") {
helpers.Deprecated("command line", "--disableRSS", "Use --disableKinds=RSS", false)
}
if flagChanged(cmd.Flags(), "disableSitemap") {
if cmd.Flags().Changed("disableSitemap") {
helpers.Deprecated("command line", "--disableSitemap", "Use --disableKinds=sitemap", false)
}
@ -489,20 +489,12 @@ func (c *commandeer) initializeFlags(cmd *cobra.Command) {
}
func (c *commandeer) setValueFromFlag(flags *flag.FlagSet, key string) {
if flagChanged(flags, key) {
if flags.Changed(key) {
f := flags.Lookup(key)
c.Set(key, f.Value.String())
}
}
func flagChanged(flags *flag.FlagSet, key string) bool {
flag := flags.Lookup(key)
if flag == nil {
return false
}
return flag.Changed
}
func (c *commandeer) watchConfig() {
v := c.Cfg.(*viper.Viper)
v.WatchConfig()

View file

@ -98,11 +98,11 @@ func NewContent(cmd *cobra.Command, args []string) error {
return err
}
if flagChanged(cmd.Flags(), "format") {
if cmd.Flags().Changed("format") {
c.Set("metaDataFormat", configFormat)
}
if flagChanged(cmd.Flags(), "editor") {
if cmd.Flags().Changed("editor") {
c.Set("newContentEditor", contentEditor)
}

View file

@ -106,7 +106,7 @@ func server(cmd *cobra.Command, args []string) error {
return err
}
if flagChanged(cmd.Flags(), "disableLiveReload") {
if cmd.Flags().Changed("disableLiveReload") {
c.Set("disableLiveReload", disableLiveReload)
}
@ -123,7 +123,7 @@ func server(cmd *cobra.Command, args []string) error {
if err == nil {
l.Close()
} else {
if flagChanged(serverCmd.Flags(), "port") {
if serverCmd.Flags().Changed("port") {
// port set explicitly by user -- he/she probably meant it!
return newSystemErrorF("Server startup failed: %s", err)
}