If the description of an option contains line breaks, subsequent lines should be indented to match the position of the first line in the help output. Otherwise, we see something like this:
--to-dir <dir> The directory where the site should be generated.
Defaults to build/site if no destinations are specified.
It would be great if the help was aware of the terminal width and wrapped lines that overflow intelligently, though I recognize that's a separate feature request.
Upvoting this, the console's width can be obtained using process.stdout.columns.
Upvoting this as well, just stumbled into this issue myself.
A caveat that a previous attempt at indenting multiline descriptions was pulled after it broke user formatted help: #396
There are improvements on the develop branch for the next release (#956 and #1051).
v4.0.0-0 prerelease published: #1067
v4.0.0 has been released.
The reliance on process.stdout.columns is problematic for tests (and other headless integrations), where the columns property may not be set on stdout. It would be helpful if the value could be overridden using the standard COLUMNS environment variable.
process.stdout.columns || process.env.COLUMNS || 80
May I propose a PR?
(The output honoring the columns value is nice looking, though).
Short version: PR welcome, thanks.
Long version
Standard, like here?
For interest, in Commander's own unit tests I set process.stdout.columns directly to get consistent behaviour.
A caveat that there is a fix coming to remove trailing space in wrapped output: #1096
Standard, like here?
Yes. Also mentioned in the bash help.
in Commander's own unit tests I set process.stdout.columns directly to get consistent behaviour.
That only works if testing the API. It doesn't work when the command is spawned. To test my application, I'm using a CLI test framework which doesn't allow me to control how the stdio is configured. So it's out of reach. The same would be true for integrations that spawn the command using commander.js.
Doing a little research, found one interesting complication that COLUMNS may be a shell variable in an interactive shell rather than an environment variable.
Potentially ok, but if find other platform/shell clashes then could use a custom name for the override like COMMANDER_COLUMNS.
I'd honestly be fine with any environment variable name, tbh. In fact, I'd even be happy if it were a method I could override. I just need it for testing / integration, so it can be rather low level. The main issue is that the call is in the middle of several functions and I have no way to get at it so I can influence it.
I am preferring COMMANDER_COLUMNS to be paranoid and avoid unexpected false positives with the generic COLUMNS. A bit clunky, but only being added for special circumstances. Overrides process.stdout.columns. Does that fit into your anticipated use cases?
Yep, that would do the trick.
I still think it makes sense to extract that bit of logic as a method since it is used a couple of times in the code. It would not only make it overriddable, but also DRY. We'd likely never hear any complaints again ;)
At this point, we should probably start a new issue as this one is already closed. Would you like me to do that, or would you prefer to do it.
Please go ahead and make a new issue. Thanks.
Extracting that bit of logic is something I considered at the time, and more logic now and more worthwhile, but I don't want to make it public. The env is the supported override mechanism.
Most helpful comment
v4.0.0 has been released.