Add SilenceUsage option to cobra command (#43)

* Add SilenceUsage option to cobra command

This patch adds `cmd.SilenceUsage` to command to stop usage output
after command validation.

Fixes https://github.com/knative/client/issues/38

* Set cmd.SilenceUsage to global cmd
This commit is contained in:
Kenjiro Nakayama 2019-03-30 04:07:53 +09:00 committed by Knative Prow Robot
parent 72ec64390b
commit e8ec699d2c
2 changed files with 6 additions and 4 deletions

View File

@ -65,6 +65,9 @@ func NewKnCommand(params ...KnParams) *cobra.Command {
Serving: Manage your services and release new software to them. Serving: Manage your services and release new software to them.
Build: Create builds and keep track of their results. Build: Create builds and keep track of their results.
Eventing: Manage event subscriptions and channels. Connect up event sources.`, Eventing: Manage event subscriptions and channels. Connect up event sources.`,
// Affects children as well
SilenceUsage: true,
} }
if p.Output != nil { if p.Output != nil {
rootCmd.SetOutput(p.Output) rootCmd.SetOutput(p.Output)

View File

@ -30,15 +30,14 @@ func NewServiceDescribeCommand(p *KnParams) *cobra.Command {
Use: "describe NAME", Use: "describe NAME",
Short: "Describe available services.", Short: "Describe available services.",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("requires the service name.")
}
client, err := p.ServingFactory() client, err := p.ServingFactory()
if err != nil { if err != nil {
return err return err
} }
if len(args) < 1 {
return errors.New("requires the service name.")
}
namespace := cmd.Flag("namespace").Value.String() namespace := cmd.Flag("namespace").Value.String()
describeService, err := client.Services(namespace).Get(args[0], v1.GetOptions{}) describeService, err := client.Services(namespace).Get(args[0], v1.GetOptions{})
if err != nil { if err != nil {