mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #82423 from sallyom/kubectl-flagerror
kubectl: remove usage info from bad flag msg, only print help tip
This commit is contained in:
commit
ea4f7853bb
@ -44,6 +44,7 @@ func ActsAsRootCommand(cmd *cobra.Command, filters []string, groups ...CommandGr
|
|||||||
CommandGroups: groups,
|
CommandGroups: groups,
|
||||||
Filtered: filters,
|
Filtered: filters,
|
||||||
}
|
}
|
||||||
|
cmd.SetFlagErrorFunc(templater.FlagErrorFunc())
|
||||||
cmd.SetUsageFunc(templater.UsageFunc())
|
cmd.SetUsageFunc(templater.UsageFunc())
|
||||||
cmd.SetHelpFunc(templater.HelpFunc())
|
cmd.SetHelpFunc(templater.HelpFunc())
|
||||||
return templater
|
return templater
|
||||||
@ -66,6 +67,18 @@ type templater struct {
|
|||||||
Filtered []string
|
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 {
|
func (templater *templater) ExposeFlags(cmd *cobra.Command, flags ...string) FlagExposer {
|
||||||
cmd.SetUsageFunc(templater.UsageFunc(flags...))
|
cmd.SetUsageFunc(templater.UsageFunc(flags...))
|
||||||
return templater
|
return templater
|
||||||
|
Loading…
Reference in New Issue
Block a user