-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Best way to wrap description text by terminal width? #1785
Comments
The command description is not currently being word-wrapped. (I thought it was!) (The wrapping got developed in #956 and was focussed on option and subcommand and argument descriptions.) |
This is doable now by subclassing the Help class. Perhaps more than you are willing to do, but I wanted to check it was possible! A trap to be aware of is that no wrapping is done if the text includes a line-feed followed by whitespace, in case the text was manually formatted already. A single line-feed followed by text is fine. const { Command, Help } = require('commander');
class MyHelp extends Help {
commandDescription(cmd) {
const description = cmd.description();
if (!description) return '';
const helpWidth = this.helpWidth || 80;
return this.wrap(description, helpWidth, 0);
}
}
class MyCommand extends Command {
createCommand(name) {
return new MyCommand(name);
}
createHelp() {
return new MyHelp;
}
}
const program = new MyCommand();
program
.description(`. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
this long line will be wrapped without breaking words across lines if there is enough room to make it worthwhile
and this text is on another line`);
program.parse(); $ node index.js -h
Usage: index [options]
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
this long line will be wrapped without breaking words across
lines if there is enough room to make it worthwhile
and this text is on another line
Options:
-h, --help display help for command |
Adding wrapping for (full) command description in #1804 |
Released in Commander v10.0.0 |
this is of minor priority
When I put in long lines in my description, they get chopped mid-word on "max 80-char width" displays; this looks bad, it's hard to read.
So I limit my description text to max 80 chars per line, but it's weird then to do
-h
and see the options take advantage of the much wider terminal, while the description is hard-coded to "max 80".How can I display descriptions according to terminal width? Ideally I only put newlines where they make semantic sense, and let another layer handle the wrapping (on words, though, not chars).
I'm hoping there is already a way to do this that I haven't found, but I haven't found it :)
The text was updated successfully, but these errors were encountered: