argv: Add support for boolean flags when equal sign is used
This commit is contained in:
parent
129e50367d
commit
2ee285e1c4
2 changed files with 21 additions and 0 deletions
|
@ -52,6 +52,8 @@ Argv.prototype.load = function () {
|
||||||
let equalSignIndex = key.indexOf('=')
|
let equalSignIndex = key.indexOf('=')
|
||||||
if (equalSignIndex > 0) {
|
if (equalSignIndex > 0) {
|
||||||
this.set(key.slice(0, equalSignIndex), key.slice(equalSignIndex + 1))
|
this.set(key.slice(0, equalSignIndex), key.slice(equalSignIndex + 1))
|
||||||
|
} else {
|
||||||
|
this.set(key, true)
|
||||||
}
|
}
|
||||||
} else if (args[i + 1] && !args[i + 1].startsWith(this.prefix)) {
|
} else if (args[i + 1] && !args[i + 1].startsWith(this.prefix)) {
|
||||||
this.set(key, args[i + 1])
|
this.set(key, args[i + 1])
|
||||||
|
|
|
@ -140,6 +140,25 @@ t.describe('#load()', () => {
|
||||||
testety: 'hello',
|
testety: 'hello',
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.test('equal sign should support boolean values', function() {
|
||||||
|
process.argv = ['bla', 'bla',
|
||||||
|
'--booleanone',
|
||||||
|
'--foobar=123',
|
||||||
|
'--testety=hello',
|
||||||
|
'--booleantwo',
|
||||||
|
]
|
||||||
|
let store = new Nconf.Argv({ useEqualsign: true })
|
||||||
|
store.load()
|
||||||
|
assert.strictEqual(store.get('booleanone'), true)
|
||||||
|
assert.strictEqual(store.get('booleantwo'), true)
|
||||||
|
assert.deepStrictEqual(store.get(), {
|
||||||
|
foobar: '123',
|
||||||
|
testety: 'hello',
|
||||||
|
booleanone: true,
|
||||||
|
booleantwo: true,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
t.test('should be smart with the usage of equal sign', function() {
|
t.test('should be smart with the usage of equal sign', function() {
|
||||||
process.argv = ['bla', 'bla',
|
process.argv = ['bla', 'bla',
|
||||||
|
|
Loading…
Reference in a new issue