From 50ae82b0cc1d3e6745ac9f66a9f9980530f29a09 Mon Sep 17 00:00:00 2001 From: David Simansky Date: Sat, 8 Feb 2020 15:48:14 +0100 Subject: [PATCH] Fix capitalization of generated flags (#638) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Roland Huß --- docs/cmd/kn_service_create.md | 4 ++-- docs/cmd/kn_service_update.md | 4 ++-- pkg/kn/commands/service/configuration_edit_flags.go | 2 +- pkg/kn/flags/bool.go | 10 ++++++++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/docs/cmd/kn_service_create.md b/docs/cmd/kn_service_create.md index 7fa7124852..74f0fd709a 100644 --- a/docs/cmd/kn_service_create.md +++ b/docs/cmd/kn_service_create.md @@ -57,12 +57,12 @@ kn service create NAME --image IMAGE [flags] -l, --label stringArray Service label to set. name=value; you may provide this flag any number of times to set multiple labels. To unset, specify the label name followed by a "-" (e.g., name-). --limits-cpu string The limits on the requested CPU (e.g., 1000m). --limits-memory string The limits on the requested memory (e.g., 1024Mi). - --lock-to-digest keep the running image for the service constant when not explicitly specifying the image. (--no-lock-to-digest pulls the image tag afresh with each new revision) (default true) + --lock-to-digest Keep the running image for the service constant when not explicitly specifying the image. (--no-lock-to-digest pulls the image tag afresh with each new revision) (default true) --max-scale int Maximal number of replicas. --min-scale int Minimal number of replicas. --mount stringArray Mount a ConfigMap (prefix cm: or config-map:), a Secret (prefix secret: or sc:), or an existing Volume (without any prefix) on the specified directory. Example: --mount /mydir=cm:myconfigmap, --mount /mydir=secret:mysecret, or --mount /mydir=myvolume. When a configmap or a secret is specified, a corresponding volume is automatically generated. You can use this flag multiple times. For unmounting a directory, append "-", e.g. --mount /mydir-, which also removes any auto-generated volume. -n, --namespace string Specify the namespace to operate in. - --no-lock-to-digest do not keep the running image for the service constant when not explicitly specifying the image. (--no-lock-to-digest pulls the image tag afresh with each new revision) + --no-lock-to-digest Do not keep the running image for the service constant when not explicitly specifying the image. (--no-lock-to-digest pulls the image tag afresh with each new revision) --no-wait Create service and don't wait for it to become ready. -p, --port int32 The port where application listens on. --pull-secret string Image pull secret to set. An empty argument ("") clears the pull secret. The referenced secret must exist in the service's namespace. diff --git a/docs/cmd/kn_service_update.md b/docs/cmd/kn_service_update.md index 1852bfa159..d854f9b26d 100644 --- a/docs/cmd/kn_service_update.md +++ b/docs/cmd/kn_service_update.md @@ -52,12 +52,12 @@ kn service update NAME [flags] -l, --label stringArray Service label to set. name=value; you may provide this flag any number of times to set multiple labels. To unset, specify the label name followed by a "-" (e.g., name-). --limits-cpu string The limits on the requested CPU (e.g., 1000m). --limits-memory string The limits on the requested memory (e.g., 1024Mi). - --lock-to-digest keep the running image for the service constant when not explicitly specifying the image. (--no-lock-to-digest pulls the image tag afresh with each new revision) (default true) + --lock-to-digest Keep the running image for the service constant when not explicitly specifying the image. (--no-lock-to-digest pulls the image tag afresh with each new revision) (default true) --max-scale int Maximal number of replicas. --min-scale int Minimal number of replicas. --mount stringArray Mount a ConfigMap (prefix cm: or config-map:), a Secret (prefix secret: or sc:), or an existing Volume (without any prefix) on the specified directory. Example: --mount /mydir=cm:myconfigmap, --mount /mydir=secret:mysecret, or --mount /mydir=myvolume. When a configmap or a secret is specified, a corresponding volume is automatically generated. You can use this flag multiple times. For unmounting a directory, append "-", e.g. --mount /mydir-, which also removes any auto-generated volume. -n, --namespace string Specify the namespace to operate in. - --no-lock-to-digest do not keep the running image for the service constant when not explicitly specifying the image. (--no-lock-to-digest pulls the image tag afresh with each new revision) + --no-lock-to-digest Do not keep the running image for the service constant when not explicitly specifying the image. (--no-lock-to-digest pulls the image tag afresh with each new revision) --no-wait Update service and don't wait for it to become ready. -p, --port int32 The port where application listens on. --pull-secret string Image pull secret to set. An empty argument ("") clears the pull secret. The referenced secret must exist in the service's namespace. diff --git a/pkg/kn/commands/service/configuration_edit_flags.go b/pkg/kn/commands/service/configuration_edit_flags.go index 041070d450..25753a8551 100644 --- a/pkg/kn/commands/service/configuration_edit_flags.go +++ b/pkg/kn/commands/service/configuration_edit_flags.go @@ -152,7 +152,7 @@ func (p *ConfigurationEditFlags) addSharedFlags(command *cobra.Command) { p.markFlagMakesRevision("revision-name") flags.AddBothBoolFlagsUnhidden(command.Flags(), &p.LockToDigest, "lock-to-digest", "", true, - "keep the running image for the service constant when not explicitly specifying "+ + "Keep the running image for the service constant when not explicitly specifying "+ "the image. (--no-lock-to-digest pulls the image tag afresh with each new revision)") // Don't mark as changing the revision. command.Flags().StringVar(&p.ServiceAccountName, diff --git a/pkg/kn/flags/bool.go b/pkg/kn/flags/bool.go index 49ec4bf44a..026638b822 100644 --- a/pkg/kn/flags/bool.go +++ b/pkg/kn/flags/bool.go @@ -18,6 +18,8 @@ import ( "fmt" "strconv" "strings" + "unicode" + "unicode/utf8" "github.com/spf13/pflag" ) @@ -30,8 +32,7 @@ func AddBothBoolFlagsUnhidden(f *pflag.FlagSet, p *bool, name, short string, val negativeName := negPrefix + name f.BoolVarP(p, name, short, value, usage) - f.Bool(negativeName, !value, "do not "+usage) - + f.Bool(negativeName, !value, "Do not "+firstCharToLower(usage)) } // AddBothBoolFlags adds the given flag in both `--foo` and `--no-foo` variants. @@ -108,3 +109,8 @@ func checkExplicitFalse(f *pflag.Flag, betterFlag string) error { } return nil } + +func firstCharToLower(s string) string { + r, n := utf8.DecodeRuneInString(s) + return string(unicode.ToLower(r)) + s[n:] +}