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

Commit

Permalink
args with hyphen (-) are not being treated #14
Browse files Browse the repository at this point in the history
  • Loading branch information
goya committed Oct 23, 2018
1 parent 5feb05e commit 4121373
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/util/args.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pgb-cli",
"version": "1.1.0",
"version": "1.1.1",
"description": "nodeJS CLI to PhoneGap Build",
"keywords": [
"PhoneGap",
Expand Down
4 changes: 2 additions & 2 deletions src/util/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = (opts) => {
let arg = rawArgs[i]
let args = arg.split('=')
let key = args.shift().toLowerCase().replace(/^--/, '')
let variable = (key in opts.variables) || args.length
let variable = args.length || (arg.startsWith('--') && (key in opts.variables))

if (variable) {
let value = (args.length) ? args.join('=') : rawArgs[++i]
Expand All @@ -33,7 +33,7 @@ module.exports = (opts) => {
variables[key] = value
}
} else if (arg.startsWith('--')) {
parseArgs([arg.slice(2)])
parseArgs([arg.replace(/-/g, '')])
} else if (arg.startsWith('-')) {
parseArgs(arg.slice(1))
} else {
Expand Down
16 changes: 16 additions & 0 deletions test/util/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ describe('args', () => {
})
})

test('should parse variables only with --blah or blah=blah', () => {
let opts = { flags: {}, aliases: {}, variables: { lock: false, foo: false } }
argv('foo lock 12 --lock b yut=9 foo bar')
return parseArgs(opts).then((result) => {
expect(result).toEqual({ commands: ['foo', 'lock', '12', 'foo', 'bar'], variables: { lock: 'b', yut: '9' } })
})
})

test('should parse variables', () => {
let opts = { flags: {}, aliases: {}, variables: {} }
argv('foo var1=abc var2=def')
Expand All @@ -75,6 +83,14 @@ describe('args', () => {
})
})

test('should parse variables with dashes in name', () => {
let opts = { flags: { 'exitcode': '' }, aliases: {}, variables: { } }
argv('foo --exit-code')
return parseArgs(opts).then((result) => {
expect(result).toEqual({ commands: [ 'foo' ], exitcode: true, variables: { } })
})
})

test('should parse variables correctly with equal signs in value', () => {
let opts = { flags: { }, aliases: {}, variables: { var1: false } }
argv('foo var1=abc var2=bar=12')
Expand Down

0 comments on commit 4121373

Please sign in to comment.