From af76d14e2e9c4467053cd6c4cb20fed39cf29812 Mon Sep 17 00:00:00 2001 From: Filipe Brandenburger Date: Wed, 21 Jan 2015 07:56:24 -0800 Subject: [PATCH 1/2] Revert "fixup repeated usage strings" This reverts commit 469bd2b6413ecdf22d7ad105a685490f39a63ae8. --- pkg/client/clientcmd/overrides.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pkg/client/clientcmd/overrides.go b/pkg/client/clientcmd/overrides.go index 51f5233d5c..597bca4a27 100644 --- a/pkg/client/clientcmd/overrides.go +++ b/pkg/client/clientcmd/overrides.go @@ -112,11 +112,10 @@ func RecommendedConfigOverrideFlags(prefix string) ConfigOverrideFlags { // BindAuthInfoFlags is a convenience method to bind the specified flags to their associated variables func BindAuthInfoFlags(authInfo *clientcmdapi.AuthInfo, flags *pflag.FlagSet, flagNames AuthOverrideFlags) { // TODO short flag names are impossible to prefix. code gets cleaner if we remove them - authPathUsage := "Path to the auth info file. If missing, prompt the user. Only used if using https." if len(flagNames.AuthPathShort) > 0 { - flags.StringVarP(&authInfo.AuthPath, flagNames.AuthPath, flagNames.AuthPathShort, "", authPathUsage) + flags.StringVarP(&authInfo.AuthPath, flagNames.AuthPath, flagNames.AuthPathShort, "", "Path to the auth info file. If missing, prompt the user. Only used if using https.") } else { - flags.StringVar(&authInfo.AuthPath, flagNames.AuthPath, "", authPathUsage) + flags.StringVar(&authInfo.AuthPath, flagNames.AuthPath, "", "Path to the auth info file. If missing, prompt the user. Only used if using https.") } flags.StringVar(&authInfo.ClientCertificate, flagNames.ClientCertificate, "", "Path to a client key file for TLS.") flags.StringVar(&authInfo.ClientKey, flagNames.ClientKey, "", "Path to a client key file for TLS.") @@ -126,11 +125,10 @@ func BindAuthInfoFlags(authInfo *clientcmdapi.AuthInfo, flags *pflag.FlagSet, fl // BindClusterFlags is a convenience method to bind the specified flags to their associated variables func BindClusterFlags(clusterInfo *clientcmdapi.Cluster, flags *pflag.FlagSet, flagNames ClusterOverrideFlags) { // TODO short flag names are impossible to prefix. code gets cleaner if we remove them - apiServerUsage := "The address of the Kubernetes API server" if len(flagNames.APIServerShort) > 0 { - flags.StringVarP(&clusterInfo.Server, flagNames.APIServer, flagNames.APIServerShort, "", apiServerUsage) + flags.StringVarP(&clusterInfo.Server, flagNames.APIServer, flagNames.APIServerShort, "", "The address of the Kubernetes API server") } else { - flags.StringVar(&clusterInfo.Server, flagNames.APIServer, "", apiServerUsage) + flags.StringVar(&clusterInfo.Server, flagNames.APIServer, "", "The address of the Kubernetes API server") } flags.StringVar(&clusterInfo.APIVersion, flagNames.APIVersion, "", "The API version to use when talking to the server") flags.StringVar(&clusterInfo.CertificateAuthority, flagNames.CertificateAuthority, "", "Path to a cert. file for the certificate authority.") From 0bfeeb84ca77e53337b9d869fbd3a735eda59d03 Mon Sep 17 00:00:00 2001 From: Filipe Brandenburger Date: Wed, 21 Jan 2015 07:58:02 -0800 Subject: [PATCH 2/2] Make short flags optional, refactor code to use StringVarP directly. There is no need to check for an empty string and call StringVar or StringVarP depending on the case, since StringVar is essentially the same as a call to StringVarP with an empty string. This turns 6 lines of code back into 1. Remove the TODO comments since removing the short flags will no longer simplify this code significantly. --- pkg/client/clientcmd/overrides.go | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/pkg/client/clientcmd/overrides.go b/pkg/client/clientcmd/overrides.go index 597bca4a27..055f1de556 100644 --- a/pkg/client/clientcmd/overrides.go +++ b/pkg/client/clientcmd/overrides.go @@ -111,12 +111,7 @@ func RecommendedConfigOverrideFlags(prefix string) ConfigOverrideFlags { // BindAuthInfoFlags is a convenience method to bind the specified flags to their associated variables func BindAuthInfoFlags(authInfo *clientcmdapi.AuthInfo, flags *pflag.FlagSet, flagNames AuthOverrideFlags) { - // TODO short flag names are impossible to prefix. code gets cleaner if we remove them - if len(flagNames.AuthPathShort) > 0 { - flags.StringVarP(&authInfo.AuthPath, flagNames.AuthPath, flagNames.AuthPathShort, "", "Path to the auth info file. If missing, prompt the user. Only used if using https.") - } else { - flags.StringVar(&authInfo.AuthPath, flagNames.AuthPath, "", "Path to the auth info file. If missing, prompt the user. Only used if using https.") - } + flags.StringVarP(&authInfo.AuthPath, flagNames.AuthPath, flagNames.AuthPathShort, "", "Path to the auth info file. If missing, prompt the user. Only used if using https.") flags.StringVar(&authInfo.ClientCertificate, flagNames.ClientCertificate, "", "Path to a client key file for TLS.") flags.StringVar(&authInfo.ClientKey, flagNames.ClientKey, "", "Path to a client key file for TLS.") flags.StringVar(&authInfo.Token, flagNames.Token, "", "Bearer token for authentication to the API server.") @@ -124,12 +119,7 @@ func BindAuthInfoFlags(authInfo *clientcmdapi.AuthInfo, flags *pflag.FlagSet, fl // BindClusterFlags is a convenience method to bind the specified flags to their associated variables func BindClusterFlags(clusterInfo *clientcmdapi.Cluster, flags *pflag.FlagSet, flagNames ClusterOverrideFlags) { - // TODO short flag names are impossible to prefix. code gets cleaner if we remove them - if len(flagNames.APIServerShort) > 0 { - flags.StringVarP(&clusterInfo.Server, flagNames.APIServer, flagNames.APIServerShort, "", "The address of the Kubernetes API server") - } else { - flags.StringVar(&clusterInfo.Server, flagNames.APIServer, "", "The address of the Kubernetes API server") - } + flags.StringVarP(&clusterInfo.Server, flagNames.APIServer, flagNames.APIServerShort, "", "The address of the Kubernetes API server") flags.StringVar(&clusterInfo.APIVersion, flagNames.APIVersion, "", "The API version to use when talking to the server") flags.StringVar(&clusterInfo.CertificateAuthority, flagNames.CertificateAuthority, "", "Path to a cert. file for the certificate authority.") flags.BoolVar(&clusterInfo.InsecureSkipTLSVerify, flagNames.InsecureSkipTLSVerify, false, "If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure.")