mirror of
https://github.com/spf13/cobra
synced 2024-11-05 05:17:12 +00:00
Properly swallowing flag error messages
This commit is contained in:
parent
1be06e4e1a
commit
ce6447a965
1 changed files with 7 additions and 0 deletions
7
cobra.go
7
cobra.go
|
@ -210,6 +210,9 @@ func (c *Command) HasParent() bool {
|
|||
func (c *Command) Flags() *flag.FlagSet {
|
||||
if c.flags == nil {
|
||||
c.flags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
||||
if c.flagErrorBuf == nil {
|
||||
c.flagErrorBuf = new(bytes.Buffer)
|
||||
}
|
||||
c.flags.SetOutput(c.flagErrorBuf)
|
||||
}
|
||||
return c.flags
|
||||
|
@ -219,6 +222,9 @@ func (c *Command) Flags() *flag.FlagSet {
|
|||
func (c *Command) PersistentFlags() *flag.FlagSet {
|
||||
if c.pflags == nil {
|
||||
c.pflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
||||
if c.flagErrorBuf == nil {
|
||||
c.flagErrorBuf = new(bytes.Buffer)
|
||||
}
|
||||
c.pflags.SetOutput(c.flagErrorBuf)
|
||||
}
|
||||
return c.flags
|
||||
|
@ -226,6 +232,7 @@ func (c *Command) PersistentFlags() *flag.FlagSet {
|
|||
|
||||
// Intended for use in testing
|
||||
func (c *Command) ResetFlags() {
|
||||
c.flagErrorBuf = new(bytes.Buffer)
|
||||
c.flags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
||||
c.flags.SetOutput(c.flagErrorBuf)
|
||||
c.pflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
||||
|
|
Loading…
Reference in a new issue