Skip to content

Commit

Permalink
Resolved incorrect value assignments to boolean flags when succeeded …
Browse files Browse the repository at this point in the history
…by an unnamed argument.
  • Loading branch information
coreybutler committed Oct 18, 2021
1 parent f10c36d commit 61938dc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@author.io/arg",
"version": "1.3.18",
"version": "1.3.19",
"description": "An argument parser for CLI applications.",
"main": "./src/index.js",
"exports": {
Expand Down
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class Parser {
unknownName = `${unknownName}${count}`
}

data[unknownName] = true
data[unknownName] = flag.value !== null ? flag.value : true
Object.defineProperty(sources, unknownName, {
enumerable: true,
get () {
Expand Down Expand Up @@ -234,9 +234,10 @@ class Parser {
if (typeof flag.value !== flag.type) {
if (flag.type === 'boolean') {
const unknownFlag = new Flag(this.#cleanFlag(`unknown${this.#unknownFlags.size + 1}`))
unknownFlag.strictTypes = false
unknownFlag.strictTypes = !this.#ignoreTypes
unknownFlag.value = flag.value
if (!this.#unknownFlags.has(unknownName.name)) {

if (!this.#unknownFlags.has(unknownFlag.name)) {
this.#unknownFlags.set(unknownFlag.name, unknownFlag)
}

Expand Down
6 changes: 3 additions & 3 deletions tests/09-regression.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ test('Non-Boolean Regression Test', t => {

const Args = new Parser(input, cfg)
const d = Args.data
t.ok(d.more === true, 'Recognized boolean flag.')
t.ok(d.t === true, 'Treat unrecognized flags separtely from boolean flag. Expected a flag called "t" to exist. Recognized: ' + d.hasOwnProperty('t'))
t.expect(true, d.more, 'Recognized boolean flag.')
t.expect(true, d.t, 'Treat unrecognized flags separtely from boolean flag. Expected a flag called "t" to exist. Recognized: ' + d.hasOwnProperty('t'))
t.end()
})

Expand Down Expand Up @@ -130,7 +130,7 @@ test('Boolean flags followed by unnamed string argument', t => {
t.expect('[email protected]', data.runtime, 'recognized string flag')
t.expect(true, data.debugmodule, 'recognized first boolean flag')
t.expect(true, data.verbose, 'recognized second boolean flag')
t.ok(data['./tests/*-*.js'] !== undefined, 'recognized unnamed string argument')
t.expect('./tests/*-*.js', data.unknown1, 'recognized unnamed string argument')

t.end()
})

0 comments on commit 61938dc

Please sign in to comment.