mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-11 20:03:58 +02:00
Add helpers.NormalizeHugoFlagsFunc() to handle flag name changes
It currently handles --baseUrl to --baseURL, and --uglyUrls to --uglyURLs. Special thanks to Eric Paris (@eparis) for writing the "normalized name" support in Cobra, and for showing us how it is used in Kubernetes. See Issue #959
This commit is contained in:
@@ -31,6 +31,7 @@ import (
|
||||
"github.com/spf13/cast"
|
||||
bp "github.com/spf13/hugo/bufferpool"
|
||||
jww "github.com/spf13/jwalterweatherman"
|
||||
"github.com/spf13/pflag"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
@@ -428,3 +429,17 @@ func DoArithmetic(a, b interface{}, op rune) (interface{}, error) {
|
||||
return nil, errors.New("There is no such an operation")
|
||||
}
|
||||
}
|
||||
|
||||
// NormalizeHugoFlagsFunc facilitates transitions of Hugo command-line flags,
|
||||
// e.g. --baseUrl to --baseURL, --uglyUrls to --uglyURLs
|
||||
func NormalizeHugoFlagsFunc(f *pflag.FlagSet, name string) pflag.NormalizedName {
|
||||
switch name {
|
||||
case "baseUrl":
|
||||
name = "baseURL"
|
||||
break
|
||||
case "uglyUrls":
|
||||
name = "uglyURLs"
|
||||
break
|
||||
}
|
||||
return pflag.NormalizedName(name)
|
||||
}
|
||||
|
Reference in New Issue
Block a user