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
Wrap and indent help descriptions for options and commands #1051
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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,122 @@ | ||
const commander = require('../'); | ||
|
||
// Test auto wrap and indent with some manual strings. | ||
|
||
test('when long option description then wrap and indent', () => { | ||
const oldColumns = process.stdout.columns; | ||
process.stdout.columns = 80; | ||
const program = new commander.Command(); | ||
program | ||
.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'); | ||
|
||
const expectedOutput = | ||
`Usage: [options] | ||
|
||
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 | ||
-h, --help output usage information | ||
`; | ||
|
||
expect(program.helpInformation()).toBe(expectedOutput); | ||
process.stdout.columns = oldColumns; | ||
}); | ||
|
||
test('when long option description and default then wrap and indent', () => { | ||
const oldColumns = process.stdout.columns; | ||
process.stdout.columns = 80; | ||
const program = new commander.Command(); | ||
program | ||
.option('-x -extra-long-option <value>', 'kjsahdkajshkahd kajhsd akhds', 'aaa bbb ccc ddd eee fff ggg'); | ||
|
||
const expectedOutput = | ||
`Usage: [options] | ||
|
||
Options: | ||
-x -extra-long-option <value> kjsahdkajshkahd kajhsd akhds (default: "aaa | ||
bbb ccc ddd eee fff ggg") | ||
-h, --help output usage information | ||
`; | ||
|
||
expect(program.helpInformation()).toBe(expectedOutput); | ||
process.stdout.columns = oldColumns; | ||
}); | ||
|
||
test('when long command description then wrap and indent', () => { | ||
const oldColumns = process.stdout.columns; | ||
process.stdout.columns = 80; | ||
const program = new commander.Command(); | ||
program | ||
.option('-x -extra-long-option-switch', 'x') | ||
.command('alpha', 'Lorem mollit quis dolor ex do eu quis ad insa a commodo esse.'); | ||
|
||
const expectedOutput = | ||
`Usage: [options] [command] | ||
|
||
Options: | ||
-x -extra-long-option-switch x | ||
-h, --help output usage information | ||
|
||
Commands: | ||
alpha Lorem mollit quis dolor ex do eu quis ad insa | ||
a commodo esse. | ||
`; | ||
|
||
expect(program.helpInformation()).toBe(expectedOutput); | ||
process.stdout.columns = oldColumns; | ||
}); | ||
|
||
test('when not enough room then help not wrapped', () => { | ||
// Not wrapping if less than 40 columns available for wrapping. | ||
const oldColumns = process.stdout.columns; | ||
process.stdout.columns = 60; | ||
const program = new commander.Command(); | ||
const commandDescription = 'description text of very long command which should not be automatically be wrapped. Do fugiat eiusmod ipsum laboris excepteur pariatur sint ullamco tempor labore eu.'; | ||
program | ||
.command('1234567801234567890x', commandDescription); | ||
|
||
const expectedOutput = | ||
`Usage: [options] [command] | ||
|
||
Options: | ||
-h, --help output usage information | ||
|
||
Commands: | ||
1234567801234567890x ${commandDescription} | ||
`; | ||
|
||
expect(program.helpInformation()).toBe(expectedOutput); | ||
process.stdout.columns = oldColumns; | ||
}); | ||
|
||
test('when option descripton preformatted then only add small indent', () => { | ||
const oldColumns = process.stdout.columns; | ||
process.stdout.columns = 80; | ||
// #396: leave custom format alone, apart from space-space indent | ||
const optionSpec = '-t, --time <HH:MM>'; | ||
const program = new commander.Command(); | ||
program | ||
.option(optionSpec, `select time | ||
|
||
Time can also be specified using special values: | ||
"dawn" - From night to sunrise. | ||
`); | ||
|
||
const expectedOutput = | ||
`Usage: [options] | ||
|
||
Options: | ||
${optionSpec} select time | ||
|
||
Time can also be specified using special values: | ||
"dawn" - From night to sunrise. | ||
|
||
-h, --help output usage information | ||
`; | ||
|
||
expect(program.helpInformation()).toBe(expectedOutput); | ||
process.stdout.columns = oldColumns; | ||
}); | ||
|
||
// test for argsDescription passed to command ???? |
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 document parameter is missing
minWidth
.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.
Prompted by this, I moved minWidth to an internal detail.