Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indent multi-line option description in help #759

Closed
mojavelinux opened this issue Jan 23, 2018 · 16 comments
Closed

Indent multi-line option description in help #759

mojavelinux opened this issue Jan 23, 2018 · 16 comments
Milestone

Comments

@mojavelinux
Copy link
Contributor

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.
@mojavelinux
Copy link
Contributor Author

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.

@MrShoenel
Copy link

Upvoting this, the console's width can be obtained using process.stdout.columns.

@ghost
Copy link

ghost commented May 11, 2018

Upvoting this as well, just stumbled into this issue myself.

@shadowspawn
Copy link
Collaborator

A caveat that a previous attempt at indenting multiline descriptions was pulled after it broke user formatted help: #396

@shadowspawn shadowspawn added this to the v4.0.0 milestone Sep 14, 2019
@shadowspawn
Copy link
Collaborator

There are improvements on the develop branch for the next release (#956 and #1051).

@shadowspawn
Copy link
Collaborator

v4.0.0-0 prerelease published: #1067

@shadowspawn
Copy link
Collaborator

v4.0.0 has been released.

@mojavelinux
Copy link
Contributor Author

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?

@mojavelinux
Copy link
Contributor Author

(The output honoring the columns value is nice looking, though).

@shadowspawn
Copy link
Collaborator

shadowspawn commented Dec 18, 2019

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

@mojavelinux
Copy link
Contributor Author

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.

@shadowspawn
Copy link
Collaborator

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.

@mojavelinux
Copy link
Contributor Author

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.

@shadowspawn
Copy link
Collaborator

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?

@mojavelinux
Copy link
Contributor Author

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.

@shadowspawn
Copy link
Collaborator

shadowspawn commented Dec 18, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants