Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Fok <foka@debian.org>2015-09-09 08:05:11 +0300
committerAnthony Fok <foka@debian.org>2015-09-13 14:20:14 +0300
commitd05b297e61774a4ad09e5f9720d21a8dbd373cd7 (patch)
tree5e7e2eed230b60943bdd4d488eeddcafa7841958 /helpers
parent833a396f6bc3f39a5ed27fdc415d5bf5ec00a686 (diff)
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
Diffstat (limited to 'helpers')
-rw-r--r--helpers/general.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/helpers/general.go b/helpers/general.go
index c6adc855a..d97c78454 100644
--- a/helpers/general.go
+++ b/helpers/general.go
@@ -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)
+}