Skip to content

Commit 29fc479

Browse files
Andrey Okonetchnikovokonet
Andrey Okonetchnikov
authored andcommitted
fix: Parse arguments with single quotes properly. Better tests.
Switched to string-argv since cli-command-parser seems to have a bug. Closes #419
1 parent 06635c6 commit 29fc479

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"dependencies": {
2828
"app-root-path": "^2.0.1",
2929
"chalk": "^2.3.1",
30-
"cli-command-parser": "^1.0.3",
3130
"commander": "^2.14.1",
3231
"cosmiconfig": "^4.0.0",
3332
"debug": "^3.1.0",
@@ -46,6 +45,7 @@
4645
"pify": "^3.0.0",
4746
"please-upgrade-node": "^3.0.1",
4847
"staged-git-files": "1.1.1",
48+
"string-argv": "^0.0.2",
4949
"stringify-object": "^3.2.2"
5050
},
5151
"devDependencies": {

src/findBin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const parse = require('cli-command-parser')
3+
const parse = require('string-argv')
44
const appRoot = require('app-root-path')
55
const npmWhich = require('npm-which')(process.cwd())
66
const checkPkgScripts = require('./checkPkgScripts')

test/findBin.spec.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,17 @@ describe('findBin', () => {
4141
})
4242

4343
it('should parse cmd and add arguments to args', () => {
44-
const { bin, args } = findBin('my-linter task --fix --string "additional argument"')
44+
const { bin, args } = findBin(
45+
'my-linter task --fix --rule \'quotes: [2, double]\' --another "[complex:argument]"'
46+
)
4547
expect(bin).toEqual('my-linter')
46-
expect(args).toEqual(['task', '--fix', '--string', 'additional argument'])
48+
expect(args).toEqual([
49+
'task',
50+
'--fix',
51+
'--rule',
52+
'quotes: [2, double]',
53+
'--another',
54+
'[complex:argument]'
55+
])
4756
})
4857
})

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -982,10 +982,6 @@ class-utils@^0.3.5:
982982
isobject "^3.0.0"
983983
static-extend "^0.1.1"
984984

985-
cli-command-parser@^1.0.3:
986-
version "1.0.3"
987-
resolved "https://registry.yarnpkg.com/cli-command-parser/-/cli-command-parser-1.0.3.tgz#377af3ce60ad2d8a34a7e5eae4b395d491b0d652"
988-
989985
cli-cursor@^1.0.1, cli-cursor@^1.0.2:
990986
version "1.0.2"
991987
resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-1.0.2.tgz#64da3f7d56a54412e59794bd62dc35295e8f2987"
@@ -4401,6 +4397,10 @@ stream-to-observable@^0.2.0:
44014397
dependencies:
44024398
any-observable "^0.2.0"
44034399

4400+
string-argv@^0.0.2:
4401+
version "0.0.2"
4402+
resolved "https://registry.yarnpkg.com/string-argv/-/string-argv-0.0.2.tgz#dac30408690c21f3c3630a3ff3a05877bdcbd736"
4403+
44044404
string-length@^2.0.0:
44054405
version "2.0.0"
44064406
resolved "https://registry.yarnpkg.com/string-length/-/string-length-2.0.0.tgz#d40dbb686a3ace960c1cffca562bf2c45f8363ed"

0 commit comments

Comments
 (0)