-
-
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
fix wrapped & indented option, command and argument descriptions #956
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
464dac5
adds wrap & indent option description according to tty columns
Ephigenia f3fec70
adds wrap & indent command description according to tty columns
Ephigenia 92114b7
adds wrap & indent argument description according to tty columns
Ephigenia 1364cf6
fix lint issues
Ephigenia da5c6fc
adds wrap & indent argument description according to tty columns
Ephigenia 25bfadc
style: fix lint error
Ephigenia 5ab2320
Merge branch 'master' into feat-wrapped-option-help
Ephigenia 2264763
fix merge artifact to recover previous changes
Ephigenia a72815b
Merge branch 'master' into feat-wrapped-option-help
Ephigenia 3c87123
fix description width, skip formatting when manual format
Ephigenia 736ee28
adds tests for testing option and command descriptions
Ephigenia fc488ea
style: removes trailing whitespice in file
Ephigenia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var program = require('../') | ||
, sinon = require('sinon').createSandbox() | ||
, should = require('should'); | ||
|
||
process.stdout.columns = 80; | ||
|
||
// test should make sure that the description text of commands and options | ||
// is wrapped at the columns width and indented correctly | ||
program | ||
.description('description of the command') | ||
.option('-x -extra-long-option-switch', 'kjsahdkajshkahd kajhsd akhds kashd kajhs dkha dkh aksd ka dkha kdh kasd ka kahs dkh sdkh askdh aksd kashdk ahsd kahs dkha skdh ') | ||
.option('-s', 'some other shorter description') | ||
.command('alpha', 'Lorem mollit quis dolor ex do eu quis ad insa a commodo esse.') | ||
.command('beta-gamma-delta', 'Consectetur tempor eiusmod occaecat veniam veniam Lorem anim reprehenderit ipsum amet.'); | ||
|
||
var expectedOutput = `Usage: [options] [command] | ||
|
||
description of the command | ||
|
||
Options: | ||
-x -extra-long-option-switch kjsahdkajshkahd kajhsd akhds kashd kajhs dkha | ||
dkh aksd ka dkha kdh kasd ka kahs dkh sdkh | ||
askdh aksd kashdk ahsd kahs dkha skdh | ||
-s some other shorter description | ||
-h, --help output usage information | ||
|
||
Commands: | ||
alpha Lorem mollit quis dolor ex do eu quis ad insa | ||
a commodo esse. | ||
beta-gamma-delta Consectetur tempor eiusmod occaecat veniam | ||
veniam Lorem anim reprehenderit ipsum amet. | ||
`; | ||
|
||
program.helpInformation().should.equal(expectedOutput); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
var program = require('../') | ||
, sinon = require('sinon').createSandbox() | ||
, should = require('should'); | ||
|
||
// test should make sure that the description is not wrapped when there’s | ||
// insufficient space for the wrapped description and every line would only | ||
// contains some words. | ||
program | ||
.command('alpha', `This text should also not be wrapped manually. Reprehenderit velit nulla nisi excepteur dolore cillum nisi reprehenderit.`) | ||
.command( | ||
'betabetabteabteabetabetabteabteabetabetabteabteabetabasdsasdfsdf', | ||
'description text of very long command should not be automatically be wrapped. Do fugiat eiusmod ipsum laboris excepteur pariatur sint ullamco tempor labore eu.' | ||
); | ||
|
||
var expectedOutput = `Usage: [options] [command] | ||
|
||
Options: | ||
-h, --help output usage information | ||
|
||
Commands: | ||
alpha This text should also not be wrapped manually. Reprehenderit velit nulla nisi excepteur dolore cillum nisi reprehenderit. | ||
betabetabteabteabetabetabteabteabetabetabteabteabetabasdsasdfsdf description text of very long command should not be automatically be wrapped. Do fugiat eiusmod ipsum laboris excepteur pariatur sint ullamco tempor labore eu. | ||
`; | ||
|
||
process.stdout.columns = 80; | ||
program.helpInformation().should.equal(expectedOutput); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
var program = require('../') | ||
, sinon = require('sinon').createSandbox() | ||
, should = require('should'); | ||
|
||
// make sure descriptions which are manually wrapped and indented are not | ||
// changed by in the output to maintain backwards compatibility to <3.0 | ||
program | ||
.option( | ||
'-t, --time <HH:MM>', | ||
`select time | ||
|
||
Time can also be specified using special values: | ||
|
||
"dawn" - From night to sunrise. | ||
"sunrise" - Time around sunrise. | ||
"morning" - From sunrise to noon. | ||
` | ||
) | ||
.option( | ||
'-d, --date <YYYY-MM-DD>', | ||
`select date` | ||
); | ||
|
||
var expectedOutput = `Usage: [options] | ||
|
||
Options: | ||
-t, --time <HH:MM> select time | ||
|
||
Time can also be specified using special values: | ||
|
||
"dawn" - From night to sunrise. | ||
"sunrise" - Time around sunrise. | ||
"morning" - From sunrise to noon. | ||
|
||
-d, --date <YYYY-MM-DD> select date | ||
-h, --help output usage information | ||
`; | ||
|
||
process.stdout.columns = 80; | ||
program.helpInformation().should.equal(expectedOutput); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value should be added to the description for optionalWrap, rather than added afterwards. I suggest a temporary variable to help with readability.
e.g.