Skip to content
Myr

[silence-errors]: adds Silence Usage

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Austin Riendeau · committed by Austin Riendeau · parent 03aabcd · Browse files · 2 files+6 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+6 added−1 removed

  • other:+6 added−1 removed

2 files+6 added−1 removed

modified:cobra_test.go+1 added
218 unmodified lines
219220func noRRSetupTestSilenced(input string) resulter {221 c := initialize()222 c.SilenceErrors = true223 c.SilenceUsage = true224 return fullTester(c, input)225}226227func noRRSetupTest(input string) resulter {
850 unmodified lines
modified:command.go+5 added-1 removed
61 unmodified lines
62 // Flags that are declared specifically by this command (not inherited).63 lflags *flag.FlagSet64 // SilenceErrors is an option to quiet errors down stream65 SilenceErrors bool66 // Silence Usage is an option to silence usage when an error occurs.67 SilenceUsage bool68 // The *Run functions are executed in the following order:69 // * PersistentPreRun()70 // * PreRun()71 // * Run()
567 unmodified lines
639640 err = cmd.execute(flags)641 if err != nil {642 // If root is silenced, all subcommands should have the same643 if !cmd.SilenceUsage && !c.SilenceUsage {644 c.Println(cmd.UsageString())645 }646 if !cmd.SilenceErrors && !c.SilenceErrors {647 if err == flag.ErrHelp {648 cmd.HelpFunc()(cmd, args)649 return nil650 }646 c.Println(cmd.UsageString())651 c.Println("Error:", err.Error())652 }653 return err654 }
520 unmodified lines