Skip to content

Commit c191692

Browse files
authored
chore(cli): send help to stdout (coder#6865)
Minimizes pesky `2>&1` when working with help.
1 parent c2a96bd commit c191692

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

cli/help.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,13 @@ var usageWantsArgRe = regexp.MustCompile(`<.*>`)
267267
// output for a given command.
268268
func helpFn() clibase.HandlerFunc {
269269
return func(inv *clibase.Invocation) error {
270-
// We buffer writes to stderr because the newlineLimiter writes one
270+
// We use stdout for help and not stderr since there's no straightforward
271+
// way to distinguish between a user error and a help request.
272+
//
273+
// We buffer writes to stdout because the newlineLimiter writes one
271274
// rune at a time.
272-
stderrBuf := bufio.NewWriter(inv.Stderr)
273-
out := newlineLimiter{w: stderrBuf, limit: 2}
275+
outBuf := bufio.NewWriter(inv.Stdout)
276+
out := newlineLimiter{w: outBuf, limit: 2}
274277
tabwriter := tabwriter.NewWriter(&out, 0, 0, 2, ' ', 0)
275278
err := usageTemplate.Execute(tabwriter, inv.Command)
276279
if err != nil {
@@ -280,7 +283,7 @@ func helpFn() clibase.HandlerFunc {
280283
if err != nil {
281284
return err
282285
}
283-
err = stderrBuf.Flush()
286+
err = outBuf.Flush()
284287
if err != nil {
285288
return err
286289
}

0 commit comments

Comments
 (0)