Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class Args {
case parseInt:
return ['<n>', parseInt]
default:
return false
return ['']
}
}

Expand Down Expand Up @@ -197,7 +197,7 @@ class Args {

// Set option defaults
for (const option of this.details.options) {
if (!option.defaultValue) {
if (typeof option.defaultValue === 'undefined') {
continue
}

Expand Down Expand Up @@ -274,14 +274,21 @@ class Args {
})[0].usage.length

for (const item of items) {
let usage = item.usage
let {usage, description, defaultValue} = item
const difference = longest - usage.length

// Compensate the difference to longest property with spaces
usage += ' '.repeat(difference)

// Add some space around it as well
parts.push(' ' + chalk.yellow(usage) + ' ' + chalk.dim(item.description))
if (typeof defaultValue !== 'undefined') {
if (typeof defaultValue === 'boolean') {
description += ` (${defaultValue ? 'enabled' : 'disabled'} by default)`
} else {
description += ` (defaults to ${JSON.stringify(defaultValue)})`
}
}
parts.push(' ' + chalk.yellow(usage) + ' ' + chalk.dim(description))
}

return parts
Expand Down Expand Up @@ -334,7 +341,7 @@ class Args {

if (version) {
// If it exists, register it as a default option
this.option('version', 'Output the version number', version)
this.option('version', 'Output the version number')

// And immediately output it if used in command line
if (this.raw.v || this.raw.version) {
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ test('command aliases', async t => {
}

result = await run('help')
const regexes = [/binary, b/, /cmd/, /-a, --abc \[value\]/]
const regexes = [/binary, b/, /cmd/, /-a, --abc \[value]/]
for (const regex of regexes) {
t.regex(result, regex)
}
Expand Down