Skip to content

Commit

Permalink
Silence long usage message for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
phanimarupaka committed Aug 6, 2020
1 parent 81ca866 commit 1c12971
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 4 additions & 3 deletions commands/configcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ func GetConfigCommand(name string) *cobra.Command {
listSetters.Example = cfgdocs.ListSettersExamples

set := SetCommand(name)
set.Short = cfgdocs.SetShort
set.Long = cfgdocs.SetShort + "\n" + cfgdocs.SetLong
set.Example = cfgdocs.SetExamples

tree := configcobra.Tree(name)
tree.Short = cfgdocs.TreeShort
Expand Down Expand Up @@ -129,6 +126,10 @@ func SetCommand(parent string) *cobra.Command {
fieldmeta.SetShortHandRef(ShortHandRef)
kustomizeCmd := configcobra.Set(parent)
setCmd := *kustomizeCmd
kustomizeCmd.Short = cfgdocs.SetShort
kustomizeCmd.Long = cfgdocs.SetShort + "\n" + cfgdocs.SetLong
kustomizeCmd.Example = cfgdocs.SetExamples
kustomizeCmd.SilenceUsage = true
var autoRun bool
setCmd.Flags().BoolVar(&autoRun, "auto-run", true,
`Automatically run functions after setting (if enabled for the package)`)
Expand Down
10 changes: 10 additions & 0 deletions run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func GetMain() *cobra.Command {

cmd.AddCommand(versionCmd)
hideFlags(cmd)
silenceUsage(cmd)
return cmd
}

Expand Down Expand Up @@ -233,6 +234,15 @@ var versionCmd = &cobra.Command{
},
}

// silenceUsage silences the usage for all the sub commands recursively
// so that we don't display long usage messages for all errors
func silenceUsage(cmd *cobra.Command) {
for _, subCmd := range cmd.Commands() {
subCmd.SilenceUsage = true
silenceUsage(subCmd)
}
}

// hideFlags hides any cobra flags that are unlikely to be used by
// customers.
func hideFlags(cmd *cobra.Command) {
Expand Down

0 comments on commit 1c12971

Please sign in to comment.