chore(cli): send help to stdout (#6865)

Minimizes pesky `2>&1` when working with help.
This commit is contained in:
Ammar Bandukwala 2023-03-31 13:51:55 -05:00 committed by GitHub
parent c2a96bdc7c
commit c191692751
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 4 deletions

View File

@ -267,10 +267,13 @@ var usageWantsArgRe = regexp.MustCompile(`<.*>`)
// output for a given command.
func helpFn() clibase.HandlerFunc {
return func(inv *clibase.Invocation) error {
// We buffer writes to stderr because the newlineLimiter writes one
// We use stdout for help and not stderr since there's no straightforward
// way to distinguish between a user error and a help request.
//
// We buffer writes to stdout because the newlineLimiter writes one
// rune at a time.
stderrBuf := bufio.NewWriter(inv.Stderr)
out := newlineLimiter{w: stderrBuf, limit: 2}
outBuf := bufio.NewWriter(inv.Stdout)
out := newlineLimiter{w: outBuf, limit: 2}
tabwriter := tabwriter.NewWriter(&out, 0, 0, 2, ' ', 0)
err := usageTemplate.Execute(tabwriter, inv.Command)
if err != nil {
@ -280,7 +283,7 @@ func helpFn() clibase.HandlerFunc {
if err != nil {
return err
}
err = stderrBuf.Flush()
err = outBuf.Flush()
if err != nil {
return err
}