Skip to content

Commit 3a5fde0

Browse files
committed
Fixed an issue with defaultValue combined with defaultOption #47
1 parent 3ccb028 commit 3a5fde0

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Describes a command-line option. Additionally, you can add `description` and `ty
161161
* [.multiple](#module_definition--OptionDefinition.OptionDefinition+multiple) : <code>boolean</code>
162162
* [.defaultOption](#module_definition--OptionDefinition.OptionDefinition+defaultOption) : <code>boolean</code>
163163
* [.defaultValue](#module_definition--OptionDefinition.OptionDefinition+defaultValue) : <code>\*</code>
164-
* [.group](#module_definition--OptionDefinition.OptionDefinition+group) : <code>string</code> &#124; <code>Array.&lt;string&gt;</code>
164+
* [.group](#module_definition--OptionDefinition.OptionDefinition+group) : <code>string</code> \| <code>Array.&lt;string&gt;</code>
165165

166166
<a name="module_definition--OptionDefinition.OptionDefinition+name"></a>
167167

@@ -305,7 +305,7 @@ An initial value for the option.
305305
**Kind**: instance property of <code>[OptionDefinition](#exp_module_definition--OptionDefinition)</code>
306306
<a name="module_definition--OptionDefinition.OptionDefinition+group"></a>
307307

308-
### option.group : <code>string</code> &#124; <code>Array.&lt;string&gt;</code>
308+
### option.group : <code>string</code> \| <code>Array.&lt;string&gt;</code>
309309
When your app has a large amount of options it makes sense to organise them in groups.
310310

311311
There are two automatic groups: `_all` (contains all options) and `_none` (contains options without a `group` specified in their definition).

lib/output.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Output {
4545
def = this.definitions.getDefault()
4646
if (def) {
4747
/* if it's not a `multiple` and the defaultOption has already been set, move on */
48-
if (!def.multiple && t.isDefined(this.output[def.name])) {
48+
if (!def.multiple && t.isDefined(this.output[def.name]) && this.output[def.name] !== def.defaultValue) {
4949
if (t.isDefined(value)) this.unknown.push(value)
5050
return true
5151
/* in the case we're setting an --option=value value on a multiple defaultOption, tag the value onto the previous unknown */

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
"author": "Lloyd Brookes <[email protected]>",
2727
"license": "MIT",
2828
"devDependencies": {
29-
"coveralls": "^2.11.15",
30-
"jsdoc-to-markdown": "^2.0.1",
29+
"coveralls": "^2.13.0",
30+
"jsdoc-to-markdown": "^3.0.0",
3131
"test-runner": "^0.3.0"
3232
},
3333
"dependencies": {

test/default-value.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,22 @@ runner.test('default value: is arrayifed if multiple set', function () {
7070
one: [ '2' ]
7171
})
7272
})
73+
74+
runner.test('default value: combined with defaultOption', function () {
75+
const defs = [
76+
{ name: 'path', defaultOption: true, defaultValue: './' },
77+
]
78+
79+
let argv = [ '--path', 'test' ]
80+
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
81+
path: 'test'
82+
})
83+
argv = [ 'test' ]
84+
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
85+
path: 'test'
86+
})
87+
argv = [ ]
88+
a.deepStrictEqual(commandLineArgs(defs, { argv }), {
89+
path: './'
90+
})
91+
})

0 commit comments

Comments
 (0)