Skip to content

Commit

Permalink
Allow for defaultOption to be set to false
Browse files Browse the repository at this point in the history
In the existing test, it will spit out an error:

```
Only one option definition can be the defaultOption
```

This is confusing if you've explictly set it to false and have no default options or one default option set to true.
  • Loading branch information
sblackstone committed Jan 26, 2022
1 parent 78bc342 commit 8920ca5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/option-definitions.mjs
Expand Up @@ -84,7 +84,7 @@ class Definitions extends Array {
)
}

const duplicateDefaultOption = hasDuplicates(this.map(def => def.defaultOption))
const duplicateDefaultOption = this.filter(def => def.defaultOption === true).length > 1;
if (duplicateDefaultOption) {
halt(
'INVALID_DEFINITIONS',
Expand Down
14 changes: 14 additions & 0 deletions test/default-option.mjs
Expand Up @@ -39,6 +39,20 @@ runner.test('defaultOption: multiple-defaultOption values spread out', function
})
})

runner.test('defaultOption: can be false', function () {
const optionDefinitions = [
{ name: 'one', defaultOption: false },
{ name: 'two', defaultOption: false },
{ name: 'files', defaultOption: true, multiple: true }
]
const argv = ['--one', '1', 'file1', 'file2', '--two', '2']
a.deepStrictEqual(commandLineArgs(optionDefinitions, { argv }), {
one: '1',
two: '2',
files: ['file1', 'file2']
})
})

runner.test('defaultOption: multiple-defaultOption values spread out 2', function () {
const optionDefinitions = [
{ name: 'one', type: Boolean },
Expand Down

0 comments on commit 8920ca5

Please sign in to comment.