Skip to content

Commit 4ceca76

Browse files
authored
fix(bin): get correct value from arg separated by equals (#449)
Fixes #431
1 parent e7c3973 commit 4ceca76

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

bin/semver.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ const main = () => {
3737
let a = argv.shift()
3838
const indexOfEqualSign = a.indexOf('=')
3939
if (indexOfEqualSign !== -1) {
40+
const value = a.slice(indexOfEqualSign + 1)
4041
a = a.slice(0, indexOfEqualSign)
41-
argv.unshift(a.slice(indexOfEqualSign + 1))
42+
argv.unshift(value)
4243
}
4344
switch (a) {
4445
case '-rv': case '-rev': case '--rev': case '--reverse':

tap-snapshots/test/bin/semver.js.test.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ exports[`test/bin/semver.js TAP inc tests > -i premajor 1.0.0 --preid=beta 1`] =
305305
Object {
306306
"code": 0,
307307
"err": "",
308-
"out": "2.0.0-0\\n",
308+
"out": "2.0.0-beta.0\\n",
309309
"signal": null,
310310
}
311311
`

test/bin/semver.js

+18
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,21 @@ t.test('coercing', t => Promise.all([
6060
['not a version', '1.2.3', '-c'],
6161
['not a version', '-c'],
6262
].map(args => t.resolveMatchSnapshot(run(args), args.join(' ')))))
63+
64+
t.test('args with equals', t => Promise.all([
65+
[['--version', '1.2.3'], '1.2.3'],
66+
[['--range', '1'], ['1.2.3'], ['2.3.4'], '1.2.3'],
67+
[['--increment', 'major'], ['1.0.0'], '2.0.0'],
68+
[['--increment', 'premajor'], ['--preid', 'beta'], ['1.0.0'], '2.0.0-beta.0'],
69+
].map(async (args) => {
70+
const expected = args.pop()
71+
const equals = args.map((a) => a.join('='))
72+
const spaces = args.reduce((acc, a) => acc.concat(a), [])
73+
const res1 = await run(equals)
74+
const res2 = await run(spaces)
75+
t.equal(res1.signal, null)
76+
t.equal(res1.code, 0)
77+
t.equal(res1.err, '')
78+
t.equal(res1.out.trim(), expected)
79+
t.strictSame(res1, res2, args.join(' '))
80+
})))

0 commit comments

Comments
 (0)