From 3eaa4b0d75598e1a57fdd27dbe791caf6aa37981 Mon Sep 17 00:00:00 2001 From: Alexander Scheel Date: Mon, 26 Sep 2022 12:15:48 -0400 Subject: [PATCH] Write explicit -help output to stdout (#17308) * Write explicit -help output to stdout Per the consensus of most programs, and mirroring the GNU Coding Standards for CLI design, when users request -help explicitly via the CLI, this should be written to stdout to allow paging of output. stderr is fine when an invalid usage triggers the help text however. In our case, mitchellh/cli helpfully adds a HelpWriter that we previously set to stderr explicitly. This writer is only called to print user-requested help text; it is not called on error cases (e.g., bad usage triggering additional help text to the user). Thus it should safely be settable to stdout, enabling pagers without additional redirects. Notably, we do have to set ErrorWriter as it defaults to initializing to the value of HelpWriter, which we want to set to stdout now, which is less useful. See also: https://www.gnu.org/prep/standards/html_node/_002d_002dhelp.html Resolves: #17004 Signed-off-by: Alexander Scheel * Add changelog Signed-off-by: Alexander Scheel Signed-off-by: Alexander Scheel --- changelog/17308.txt | 3 +++ command/main.go | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 changelog/17308.txt diff --git a/changelog/17308.txt b/changelog/17308.txt new file mode 100644 index 000000000..5a2bf8bac --- /dev/null +++ b/changelog/17308.txt @@ -0,0 +1,3 @@ +```release-note:improvement: +cli: User-requested -help text now appears on stdout for paging rather than stderr +``` diff --git a/command/main.go b/command/main.go index 4a5e80282..1ac728750 100644 --- a/command/main.go +++ b/command/main.go @@ -228,7 +228,8 @@ func RunCustom(args []string, runOpts *RunOptions) int { HelpFunc: groupedHelpFunc( cli.BasicHelpFunc("vault"), ), - HelpWriter: runOpts.Stderr, + HelpWriter: runOpts.Stdout, + ErrorWriter: runOpts.Stderr, HiddenCommands: hiddenCommands, Autocomplete: true, AutocompleteNoDefaultFlags: true,