Skip to content

Commit

Permalink
Fixed regression with multi-value flags
Browse files Browse the repository at this point in the history
  • Loading branch information
coreybutler committed Aug 4, 2021
1 parent 21fd02b commit 5c7c242
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 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.13",
"version": "1.3.14",
"description": "An argument parser for CLI applications.",
"main": "src/index.js",
"exports": {
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ class Parser {
this.#length = flags.length + args.length

for (const arg of flags) {
this.#flagRef(arg.flag).value = arg.value
let ref = this.#flagRef(arg.flag)
if (ref.aliasOf) {
ref = ref.aliasOf
}
ref.value = arg.value
}

for (const arg of args) {
Expand Down
18 changes: 16 additions & 2 deletions tests/09-regression.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ test('Non-Boolean Regression Test', t => {
t.end()
})

test('Flag values with spaces', t => {
test('Spaces in flag values', t => {
const input = 'test -c "my connection"'
const cfg = {
connection: {
Expand All @@ -75,4 +75,18 @@ test('Flag values with spaces', t => {

t.expect('my connection', data.connection, 'Extract escaped values with spaces')
t.end()
})
})

test('Multi-value flags', t => {
const input = 'test -f a.js -f b.js'
const cfg = {
file: {
alias: 'f',
allowMultipleValues: true
}
}
const { data } = new Parser(input, cfg)

t.expect(2, data.file.length, 'Extract multiple values')
t.end()
})

0 comments on commit 5c7c242

Please sign in to comment.