mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
cmd: Replace flagChanged with pflag.FlagSet.Changed
This commit is contained in:
parent
0a40cb43ea
commit
421a46947a
3 changed files with 8 additions and 16 deletions
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue