-
Notifications
You must be signed in to change notification settings - Fork 40k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kubectl: remove usage info from bad flag msg, only print help tip #82423
Conversation
Hi @sallyom. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
example with PR: $ kubectl config --foo
Error: unknown flag: --foo
See 'kubectl config --help' for usage. $ kubectl config view --foo
Error: unknown flag: --foo
See 'kubectl config view --help' for usage.
example without: $ kubectl config --foo
Error: unknown flag: --foo
Available Commands:
current-context Displays the current-context
delete-cluster Delete the specified cluster from the kubeconfig
delete-context Delete the specified context from the kubeconfig
get-clusters Display clusters defined in the kubeconfig
get-contexts Describe one or many contexts
rename-context Renames a context from the kubeconfig file.
set Sets an individual value in a kubeconfig file
set-cluster Sets a cluster entry in kubeconfig
set-context Sets a context entry in kubeconfig
set-credentials Sets a user entry in kubeconfig
unset Unsets an individual value in a kubeconfig file
use-context Sets the current-context in a kubeconfig file
view Display merged kubeconfig settings or a specified kubeconfig file
Usage:
kubectl config SUBCOMMAND [options]
Use "kubectl <command> --help" for more information about a given command.
Use "kubectl options" for a list of global command-line options (applies to all commands).
$ kubectl config view --foo
Error: unknown flag: --foo
Examples:
# Show merged kubeconfig settings.
kubectl config view
# Show merged kubeconfig settings and raw certificate data.
kubectl config view --raw
# Get the password for the e2e user
kubectl config view -o jsonpath='{.users[?(@.name == "e2e")].user.password}'
Options:
--allow-missing-template-keys=true: If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.
--flatten=false: Flatten the resulting kubeconfig file into self-contained output (useful for creating portable kubeconfig files)
--merge=true: Merge the full hierarchy of kubeconfig files
--minify=false: Remove all information not used by current-context from the output
-o, --output='yaml': Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.
--raw=false: Display raw byte data
--template='': Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
Usage:
kubectl config view [flags] [options]
Use "kubectl options" for a list of global command-line options (applies to all commands).
|
9a2bc5c
to
94ea22b
Compare
noticed $ kubectl options --foo
unknown flag: --foo
Run 'kubectl options' without flags. |
/ok-to-test |
94ea22b
to
0897cd2
Compare
/test pull-kubernetes-integration |
@@ -66,6 +66,29 @@ type templater struct { | |||
Filtered []string | |||
} | |||
|
|||
type FlagError struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd replace all of this with just:
func (templater *templater) FlagErrorFunc(exposedFlags ...string) func(*cobra.Command, error) error {
return func(c *cobra.Command, err error) error {
c.SilenceUsage = true
return fmt.Errorf("%s\nSee '%s --help' for usage.", err, c.CommandPath())
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😃 yup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made the above change-it's much better, but with only this change something bugs me:
$ kubectl options --foo
Error: unknown flag: --foo
See 'kubectl options --help' for usage.
but kubectl options --help
returns nothing.
I added a special case for the options --badflag to get:
$ kubectl options --foo
Error: unknown flag: --foo
Run 'kubectl options' without flags.
@@ -52,12 +52,6 @@ const ( | |||
{{ if $visibleFlags.HasFlags}}{{trimRight (flagsUsages $visibleFlags)}}{{end}}{{ if $explicitlyExposedFlags.HasFlags}}{{ if $visibleFlags.HasFlags}} | |||
{{end}}{{trimRight (flagsUsages $explicitlyExposedFlags)}}{{end}} | |||
|
|||
{{end}}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave these as is, this way when you apply the previous suggestion and run just kubectl
you'll get nice info what kubectl
is, w/o it you won't. Compare yours output with:
$ kubectl
kubectl controls the Kubernetes cluster manager.
Find more information at: https://kubernetes.io/docs/reference/kubectl/overview/
...
yours is missing above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
0897cd2
to
e36dc3a
Compare
thanks for the review @soltysh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve
/priority important-longterm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: sallyom, soltysh The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
kubectl: remove usage info from bad flag msg, only print help tip
kubectl: remove usage info from bad flag msg, only print help tip Kubernetes-commit: ea4f785
/kind cleanup
What this PR does / why we need it:
kubectl cmds have many options/flags. When a user passes a bad flag, cmd should only output a tip to run --help, rather than print the usage info.
Which issue(s) this PR fixes:
Fixes #66572
Does this PR introduce a user-facing change?:
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: