mirror of
https://github.com/coder/coder.git
synced 2025-07-18 14:17:22 +00:00
chore(cli): send help to stdout (#6865)
Minimizes pesky `2>&1` when working with help.
This commit is contained in:
11
cli/help.go
11
cli/help.go
@ -267,10 +267,13 @@ var usageWantsArgRe = regexp.MustCompile(`<.*>`)
|
|||||||
// output for a given command.
|
// output for a given command.
|
||||||
func helpFn() clibase.HandlerFunc {
|
func helpFn() clibase.HandlerFunc {
|
||||||
return func(inv *clibase.Invocation) error {
|
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.
|
// rune at a time.
|
||||||
stderrBuf := bufio.NewWriter(inv.Stderr)
|
outBuf := bufio.NewWriter(inv.Stdout)
|
||||||
out := newlineLimiter{w: stderrBuf, limit: 2}
|
out := newlineLimiter{w: outBuf, limit: 2}
|
||||||
tabwriter := tabwriter.NewWriter(&out, 0, 0, 2, ' ', 0)
|
tabwriter := tabwriter.NewWriter(&out, 0, 0, 2, ' ', 0)
|
||||||
err := usageTemplate.Execute(tabwriter, inv.Command)
|
err := usageTemplate.Execute(tabwriter, inv.Command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -280,7 +283,7 @@ func helpFn() clibase.HandlerFunc {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = stderrBuf.Flush()
|
err = outBuf.Flush()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user