Skip to content

fix(bin): get correct value from arg separated by equals #449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(bin): get correct value from arg separated by equals
Fixes #431
  • Loading branch information
lukekarrys committed Apr 10, 2022
commit 17185823c97d1aebee7e3ca747cb6f69fcb0e561
3 changes: 2 additions & 1 deletion bin/semver.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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(' '))
})))