Skip to content

Commit

Permalink
Change min offset in help
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Jan 4, 2020
1 parent 1e0db9c commit 9973491
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/help.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const MAX_LINE_WIDTH = process.stdout.columns || 200;
const MIN_OFFSET = 25;
const MIN_OFFSET = 20;
const reAstral = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
const ansiRegex = /\x1B\[([0-9]{1,3}(;[0-9]{1,3})*)?[m|K]/g;
const byName = (a, b) => a.name > b.name || -(a.name < b.name);
Expand Down Expand Up @@ -67,7 +67,7 @@ function args(params, fn = s => s) {
}

function formatLines(lines) {
const maxNameLength = Math.max(MIN_OFFSET - 2, ...lines.map(line => stringLength(line.name)));
const maxNameLength = Math.max(MIN_OFFSET, ...lines.map(line => stringLength(line.name)));

return lines.map(line => (
' ' + pad(maxNameLength, line.name) +
Expand Down
28 changes: 16 additions & 12 deletions test/command-help.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Command help', () => {
'',
'Options:',
'',
' \u001b[33m-h\u001b[39m, \u001b[33m--help\u001b[39m Output usage information',
' \u001b[33m-h\u001b[39m, \u001b[33m--help\u001b[39m Output usage information',
'',
''
].join('\n'));
Expand All @@ -42,8 +42,8 @@ describe('Command help', () => {
'',
'Options:',
'',
' \u001b[33m--foo\u001b[39m Foo',
' \u001b[33m--help\u001b[39m Output usage information',
' \u001b[33m--foo\u001b[39m Foo',
' \u001b[33m--help\u001b[39m Output usage information',
'',
''
].join('\n'));
Expand All @@ -54,9 +54,12 @@ describe('Command help', () => {
.command('test', '[qux]')
.description('Test description')
.option('-f, --foo', 'Foo')
.option('--bar <baz>', 'Bar')
.option('--bar <baz>', 'Bar', 8080)
.command('nested')
.end()
.command('nested2')
.description('with description')
.end()
.run(['--help']);

assert.equal(inspect.output, [
Expand All @@ -68,13 +71,14 @@ describe('Command help', () => {
'',
'Commands:',
'',
' \u001b[32mnested\u001b[39m ',
' \u001b[32mnested\u001b[39m ',
' \u001b[32mnested2\u001b[39m with description',
'',
'Options:',
'',
' \u001b[33m--bar\u001b[39m <baz> Bar',
' \u001b[33m-f\u001b[39m, \u001b[33m--foo\u001b[39m Foo',
' \u001b[33m-h\u001b[39m, \u001b[33m--help\u001b[39m Output usage information',
' \u001b[33m--bar\u001b[39m <baz> Bar',
' \u001b[33m-f\u001b[39m, \u001b[33m--foo\u001b[39m Foo',
' \u001b[33m-h\u001b[39m, \u001b[33m--help\u001b[39m Output usage information',
'',
''
].join('\n'));
Expand All @@ -96,8 +100,8 @@ describe('Command help', () => {
'',
'Options:',
'',
' \u001b[33m--bar\u001b[39m <baz> Bar',
' \u001b[33m-h\u001b[39m, \u001b[33m--help\u001b[39m Output usage information',
' \u001b[33m--bar\u001b[39m <baz> Bar',
' \u001b[33m-h\u001b[39m, \u001b[33m--help\u001b[39m Output usage information',
'',
''
].join('\n'));
Expand All @@ -117,8 +121,8 @@ describe('Command help', () => {
'',
'Options:',
'',
' \u001b[33m-f\u001b[39m, \u001b[33m--foo\u001b[39m Foo',
' \u001b[33m-h\u001b[39m, \u001b[33m--help\u001b[39m Output usage information',
' \u001b[33m-f\u001b[39m, \u001b[33m--foo\u001b[39m Foo',
' \u001b[33m-h\u001b[39m, \u001b[33m--help\u001b[39m Output usage information',
'',
''
].join('\n'));
Expand Down

0 comments on commit 9973491

Please sign in to comment.