considering stderr in UsageString

This commit is contained in:
Juan Leni
2019-05-15 18:49:16 +02:00
committed by Steve Francia
parent e35034f0da
commit b635726081
2 changed files with 26 additions and 1 deletions

View File

@ -384,13 +384,22 @@ func (c *Command) Help() error {
return nil
}
// UsageString return usage string.
// UsageString returns usage string.
func (c *Command) UsageString() string {
// Storing normal writers
tmpOutput := c.outWriter
tmpErr := c.errWriter
bb := new(bytes.Buffer)
c.outWriter = bb
c.errWriter = bb
c.Usage()
// Setting things back to normal
c.outWriter = tmpOutput
c.errWriter = tmpErr
return bb.String()
}