Skip to content

Commit

Permalink
Merge pull request kubernetes#82423 from sallyom/kubectl-flagerror
Browse files Browse the repository at this point in the history
kubectl: remove usage info from bad flag msg, only print help tip

Kubernetes-commit: ea4f785
  • Loading branch information
k8s-publishing-bot committed Oct 9, 2019
2 parents 340a90f + 56a4f6e commit 0c7708b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ require (
gotest.tools v2.2.0+incompatible // indirect
k8s.io/api v0.0.0-20191005115622-2e41325d9e4b
k8s.io/apimachinery v0.0.0-20191006235458-f9f2f3f8ab02
k8s.io/cli-runtime v0.0.0-20191005121332-4d28aef60981
k8s.io/client-go v0.0.0-20191006235818-c918cd02a1a3
k8s.io/component-base v0.0.0-20191005120246-f5216b94ab44
k8s.io/cli-runtime v0.0.0-20191008080826-509327b2d966
k8s.io/client-go v0.0.0-20191008115822-1210218b4a26
k8s.io/component-base v0.0.0-20191008075918-86c6082c6a20
k8s.io/klog v1.0.0
k8s.io/kube-openapi v0.0.0-20190816220812-743ec37842bf
k8s.io/metrics v0.0.0-20191005121233-894d8cc77c5e
Expand All @@ -58,9 +58,9 @@ replace (
golang.org/x/time => golang.org/x/time v0.0.0-20161028155119-f51c12702a4d
k8s.io/api => k8s.io/api v0.0.0-20191005115622-2e41325d9e4b
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20191006235458-f9f2f3f8ab02
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20191005121332-4d28aef60981
k8s.io/client-go => k8s.io/client-go v0.0.0-20191006235818-c918cd02a1a3
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20191008080826-509327b2d966
k8s.io/client-go => k8s.io/client-go v0.0.0-20191008115822-1210218b4a26
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20191003035328-700b1226c0bd
k8s.io/component-base => k8s.io/component-base v0.0.0-20191005120246-f5216b94ab44
k8s.io/component-base => k8s.io/component-base v0.0.0-20191008075918-86c6082c6a20
k8s.io/metrics => k8s.io/metrics v0.0.0-20191005121233-894d8cc77c5e
)
6 changes: 3 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,10 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/api v0.0.0-20191005115622-2e41325d9e4b/go.mod h1:V9fqJJO3eGaWUKb9e6wH3fx7JXl1IaSC1VhSLk7GJjA=
k8s.io/apimachinery v0.0.0-20191006235458-f9f2f3f8ab02/go.mod h1:92mWDd8Ji2sw2157KIgino5wCxffA8KSvhW2oY4ypdw=
k8s.io/cli-runtime v0.0.0-20191005121332-4d28aef60981/go.mod h1:CICkH37E5f4cPVqJ/ZcIDn/kdvjJHq8sacFCdCyKHtU=
k8s.io/client-go v0.0.0-20191006235818-c918cd02a1a3/go.mod h1:y9Rvsae8RfW0HpclmE1lCx4wUxrLDRhXv9gh8SWYhvc=
k8s.io/cli-runtime v0.0.0-20191008080826-509327b2d966/go.mod h1:+x62LyqVaCTt09BMn1pTlv+hopotj6eDI6xDVQ7V3rw=
k8s.io/client-go v0.0.0-20191008115822-1210218b4a26/go.mod h1:Ej3Cs9QxIg8+T2Y4v/Bh8DVv/JNYZrix9UwRQDG49ck=
k8s.io/code-generator v0.0.0-20191003035328-700b1226c0bd/go.mod h1:HC9p4y3SBN+txSs8x57qmNPXFZ/CxdCHiDTNnocCSEw=
k8s.io/component-base v0.0.0-20191005120246-f5216b94ab44/go.mod h1:vczWDSFYXxd5GBHBZnq89a2XZiLBK59t2JpoadwKV8o=
k8s.io/component-base v0.0.0-20191008075918-86c6082c6a20/go.mod h1:igCPGAZkiLboFObJH55AZAiStdoMZRsCN14ENO28iGQ=
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/gengo v0.0.0-20190822140433-26a664648505/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
Expand Down
13 changes: 13 additions & 0 deletions pkg/util/templates/templater.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func ActsAsRootCommand(cmd *cobra.Command, filters []string, groups ...CommandGr
CommandGroups: groups,
Filtered: filters,
}
cmd.SetFlagErrorFunc(templater.FlagErrorFunc())
cmd.SetUsageFunc(templater.UsageFunc())
cmd.SetHelpFunc(templater.HelpFunc())
return templater
Expand All @@ -66,6 +67,18 @@ type templater struct {
Filtered []string
}

func (templater *templater) FlagErrorFunc(exposedFlags ...string) func(*cobra.Command, error) error {
return func(c *cobra.Command, err error) error {
c.SilenceUsage = true
switch c.CalledAs() {
case "options":
return fmt.Errorf("%s\nRun '%s' without flags.", err, c.CommandPath())
default:
return fmt.Errorf("%s\nSee '%s --help' for usage.", err, c.CommandPath())
}
}
}

func (templater *templater) ExposeFlags(cmd *cobra.Command, flags ...string) FlagExposer {
cmd.SetUsageFunc(templater.UsageFunc(flags...))
return templater
Expand Down

0 comments on commit 0c7708b

Please sign in to comment.