From 4806160c519c67e5ea4b31f6add581e56f074fe3 Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Fri, 20 Feb 2015 10:20:11 -0500 Subject: [PATCH] use the cobra inherrited flags instead of implementing it --- cmd/gendocs/gen_kubectl_docs.go | 36 ++------------------------ docs/kubectl-config-set-cluster.md | 9 ------- docs/kubectl-config-set-context.md | 8 ------ docs/kubectl-config-set-credentials.md | 11 -------- 4 files changed, 2 insertions(+), 62 deletions(-) diff --git a/cmd/gendocs/gen_kubectl_docs.go b/cmd/gendocs/gen_kubectl_docs.go index 61a8cfca3be..f6ec0a2d056 100644 --- a/cmd/gendocs/gen_kubectl_docs.go +++ b/cmd/gendocs/gen_kubectl_docs.go @@ -26,42 +26,10 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd" "github.com/spf13/cobra" - "github.com/spf13/pflag" ) -func mergeFlags(old, newFlags *pflag.FlagSet) *pflag.FlagSet { - newFlags.VisitAll(func(f *pflag.Flag) { - if old.Lookup(f.Name) == nil { - old.AddFlag(f) - } - }) - return old -} - -func parentFlags(c *cobra.Command) *pflag.FlagSet { - if !c.HasParent() { - return pflag.NewFlagSet("empty", pflag.ExitOnError) - } - return mergeFlags(c.Parent().PersistentFlags(), parentFlags(c.Parent())) -} - -func myFlags(c *cobra.Command) *pflag.FlagSet { - myFlags := c.Flags() - parentFlags := parentFlags(c) - - if c.HasPersistentFlags() { - c.PersistentFlags().VisitAll(func(f *pflag.Flag) { - if c.Flags().Lookup(f.Name) == nil && - parentFlags.Lookup(f.Name) == nil { - myFlags.AddFlag(f) - } - }) - } - return myFlags -} - func printOptions(out *bytes.Buffer, command *cobra.Command, name string) { - flags := myFlags(command) + flags := command.NonInheritedFlags() flags.SetOutput(out) if command.Runnable() { fmt.Fprintf(out, "%s\n\n", command.UseLine()) @@ -72,7 +40,7 @@ func printOptions(out *bytes.Buffer, command *cobra.Command, name string) { fmt.Fprintf(out, "```\n\n") } - parentFlags := parentFlags(command) + parentFlags := command.InheritedFlags() parentFlags.SetOutput(out) if parentFlags.HasFlags() { fmt.Fprintf(out, "### Options inherrited from parent commands\n\n```\n") diff --git a/docs/kubectl-config-set-cluster.md b/docs/kubectl-config-set-cluster.md index 8eb452e0749..858a250b658 100644 --- a/docs/kubectl-config-set-cluster.md +++ b/docs/kubectl-config-set-cluster.md @@ -13,15 +13,6 @@ Sets a cluster entry in .kubeconfig kubectl config set-cluster name [--server=server] [--certificate-authority=path/to/certficate/authority] [--api-version=apiversion] [--insecure-skip-tls-verify=true] -### Options - -``` - --api-version=: api-version for the cluster entry in .kubeconfig - --certificate-authority=: certificate-authority for the cluster entry in .kubeconfig - --insecure-skip-tls-verify=false: insecure-skip-tls-verify for the cluster entry in .kubeconfig - --server=: server for the cluster entry in .kubeconfig -``` - ### Options inherrited from parent commands ``` diff --git a/docs/kubectl-config-set-context.md b/docs/kubectl-config-set-context.md index 31e3dec4ecd..f0c9740705b 100644 --- a/docs/kubectl-config-set-context.md +++ b/docs/kubectl-config-set-context.md @@ -13,14 +13,6 @@ Sets a context entry in .kubeconfig kubectl config set-context name [--cluster=cluster-nickname] [--user=user-nickname] [--namespace=namespace] -### Options - -``` - --cluster=: cluster for the context entry in .kubeconfig - --namespace=: namespace for the context entry in .kubeconfig - --user=: user for the context entry in .kubeconfig -``` - ### Options inherrited from parent commands ``` diff --git a/docs/kubectl-config-set-credentials.md b/docs/kubectl-config-set-credentials.md index 09af3e93d6d..3bde7a29593 100644 --- a/docs/kubectl-config-set-credentials.md +++ b/docs/kubectl-config-set-credentials.md @@ -26,17 +26,6 @@ Sets a user entry in .kubeconfig kubectl config set-credentials name [--auth-path=authfile] [--client-certificate=certfile] [--client-key=keyfile] [--token=bearer_token] [--username=basic_user] [--password=basic_password] -### Options - -``` - --auth-path=: auth-path for the user entry in .kubeconfig - --client-certificate=: client-certificate for the user entry in .kubeconfig - --client-key=: client-key for the user entry in .kubeconfig - --password=: password for the user entry in .kubeconfig - --token=: token for the user entry in .kubeconfig - --username=: username for the user entry in .kubeconfig -``` - ### Options inherrited from parent commands ```