Skip to content

Commit

Permalink
fix(bin): get correct value from arg separated by equals
Browse files Browse the repository at this point in the history
Fixes #431
  • Loading branch information
lukekarrys committed Apr 10, 2022
1 parent 85b269a commit 1718582
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion bin/semver.js
Expand Up @@ -37,8 +37,9 @@ const main = () => {
let a = argv.shift()
const indexOfEqualSign = a.indexOf('=')
if (indexOfEqualSign !== -1) {
const value = a.slice(indexOfEqualSign + 1)
a = a.slice(0, indexOfEqualSign)
argv.unshift(a.slice(indexOfEqualSign + 1))
argv.unshift(value)
}
switch (a) {
case '-rv': case '-rev': case '--rev': case '--reverse':
Expand Down
2 changes: 1 addition & 1 deletion tap-snapshots/test/bin/semver.js.test.cjs
Expand Up @@ -305,7 +305,7 @@ exports[`test/bin/semver.js TAP inc tests > -i premajor 1.0.0 --preid=beta 1`] =
Object {
"code": 0,
"err": "",
"out": "2.0.0-0\\n",
"out": "2.0.0-beta.0\\n",
"signal": null,
}
`
Expand Down
18 changes: 18 additions & 0 deletions test/bin/semver.js
Expand Up @@ -60,3 +60,21 @@ t.test('coercing', t => Promise.all([
['not a version', '1.2.3', '-c'],
['not a version', '-c'],
].map(args => t.resolveMatchSnapshot(run(args), args.join(' ')))))

t.test('args with equals', t => Promise.all([
[['--version', '1.2.3'], '1.2.3'],
[['--range', '1'], ['1.2.3'], ['2.3.4'], '1.2.3'],
[['--increment', 'major'], ['1.0.0'], '2.0.0'],
[['--increment', 'premajor'], ['--preid', 'beta'], ['1.0.0'], '2.0.0-beta.0'],
].map(async (args) => {
const expected = args.pop()
const equals = args.map((a) => a.join('='))
const spaces = args.reduce((acc, a) => acc.concat(a), [])
const res1 = await run(equals)
const res2 = await run(spaces)
t.equal(res1.signal, null)
t.equal(res1.code, 0)
t.equal(res1.err, '')
t.equal(res1.out.trim(), expected)
t.strictSame(res1, res2, args.join(' '))
})))

0 comments on commit 1718582

Please sign in to comment.