Skip to content
This repository was archived by the owner on May 14, 2021. It is now read-only.

Commit 4121373

Browse files
committed
args with hyphen (-) are not being treated #14
1 parent 5feb05e commit 4121373

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

lib/util/args.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pgb-cli",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "nodeJS CLI to PhoneGap Build",
55
"keywords": [
66
"PhoneGap",

src/util/args.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = (opts) => {
2323
let arg = rawArgs[i]
2424
let args = arg.split('=')
2525
let key = args.shift().toLowerCase().replace(/^--/, '')
26-
let variable = (key in opts.variables) || args.length
26+
let variable = args.length || (arg.startsWith('--') && (key in opts.variables))
2727

2828
if (variable) {
2929
let value = (args.length) ? args.join('=') : rawArgs[++i]
@@ -33,7 +33,7 @@ module.exports = (opts) => {
3333
variables[key] = value
3434
}
3535
} else if (arg.startsWith('--')) {
36-
parseArgs([arg.slice(2)])
36+
parseArgs([arg.replace(/-/g, '')])
3737
} else if (arg.startsWith('-')) {
3838
parseArgs(arg.slice(1))
3939
} else {

test/util/args.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ describe('args', () => {
6767
})
6868
})
6969

70+
test('should parse variables only with --blah or blah=blah', () => {
71+
let opts = { flags: {}, aliases: {}, variables: { lock: false, foo: false } }
72+
argv('foo lock 12 --lock b yut=9 foo bar')
73+
return parseArgs(opts).then((result) => {
74+
expect(result).toEqual({ commands: ['foo', 'lock', '12', 'foo', 'bar'], variables: { lock: 'b', yut: '9' } })
75+
})
76+
})
77+
7078
test('should parse variables', () => {
7179
let opts = { flags: {}, aliases: {}, variables: {} }
7280
argv('foo var1=abc var2=def')
@@ -75,6 +83,14 @@ describe('args', () => {
7583
})
7684
})
7785

86+
test('should parse variables with dashes in name', () => {
87+
let opts = { flags: { 'exitcode': '' }, aliases: {}, variables: { } }
88+
argv('foo --exit-code')
89+
return parseArgs(opts).then((result) => {
90+
expect(result).toEqual({ commands: [ 'foo' ], exitcode: true, variables: { } })
91+
})
92+
})
93+
7894
test('should parse variables correctly with equal signs in value', () => {
7995
let opts = { flags: { }, aliases: {}, variables: { var1: false } }
8096
argv('foo var1=abc var2=bar=12')

0 commit comments

Comments
 (0)