Skip to content

Commit

Permalink
fix: Parse arguments with single quotes properly. Better tests.
Browse files Browse the repository at this point in the history
Switched to string-argv since cli-command-parser seems to have a bug.

Closes #419
  • Loading branch information
Andrey Okonetchnikov authored and okonet committed Apr 5, 2018
1 parent 06635c6 commit 29fc479
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -27,7 +27,6 @@
"dependencies": {
"app-root-path": "^2.0.1",
"chalk": "^2.3.1",
"cli-command-parser": "^1.0.3",
"commander": "^2.14.1",
"cosmiconfig": "^4.0.0",
"debug": "^3.1.0",
Expand All @@ -46,6 +45,7 @@
"pify": "^3.0.0",
"please-upgrade-node": "^3.0.1",
"staged-git-files": "1.1.1",
"string-argv": "^0.0.2",
"stringify-object": "^3.2.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/findBin.js
@@ -1,6 +1,6 @@
'use strict'

const parse = require('cli-command-parser')
const parse = require('string-argv')
const appRoot = require('app-root-path')
const npmWhich = require('npm-which')(process.cwd())
const checkPkgScripts = require('./checkPkgScripts')
Expand Down
13 changes: 11 additions & 2 deletions test/findBin.spec.js
Expand Up @@ -41,8 +41,17 @@ describe('findBin', () => {
})

it('should parse cmd and add arguments to args', () => {
const { bin, args } = findBin('my-linter task --fix --string "additional argument"')
const { bin, args } = findBin(
'my-linter task --fix --rule \'quotes: [2, double]\' --another "[complex:argument]"'
)
expect(bin).toEqual('my-linter')
expect(args).toEqual(['task', '--fix', '--string', 'additional argument'])
expect(args).toEqual([
'task',
'--fix',
'--rule',
'quotes: [2, double]',
'--another',
'[complex:argument]'
])
})
})
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -982,10 +982,6 @@ class-utils@^0.3.5:
isobject "^3.0.0"
static-extend "^0.1.1"

cli-command-parser@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/cli-command-parser/-/cli-command-parser-1.0.3.tgz#377af3ce60ad2d8a34a7e5eae4b395d491b0d652"

cli-cursor@^1.0.1, cli-cursor@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-1.0.2.tgz#64da3f7d56a54412e59794bd62dc35295e8f2987"
Expand Down Expand Up @@ -4401,6 +4397,10 @@ stream-to-observable@^0.2.0:
dependencies:
any-observable "^0.2.0"

string-argv@^0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/string-argv/-/string-argv-0.0.2.tgz#dac30408690c21f3c3630a3ff3a05877bdcbd736"

string-length@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/string-length/-/string-length-2.0.0.tgz#d40dbb686a3ace960c1cffca562bf2c45f8363ed"
Expand Down

0 comments on commit 29fc479

Please sign in to comment.