From 29fc479a763c1ea84289a1ab7511f9b1ef8b4d42 Mon Sep 17 00:00:00 2001 From: Andrey Okonetchnikov Date: Wed, 4 Apr 2018 20:58:13 +0200 Subject: [PATCH] fix: Parse arguments with single quotes properly. Better tests. Switched to string-argv since cli-command-parser seems to have a bug. Closes #419 --- package.json | 2 +- src/findBin.js | 2 +- test/findBin.spec.js | 13 +++++++++++-- yarn.lock | 8 ++++---- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index e75d9e5f3..e5ba96062 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": { diff --git a/src/findBin.js b/src/findBin.js index df9f6dc4e..5d30cbcad 100644 --- a/src/findBin.js +++ b/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') diff --git a/test/findBin.spec.js b/test/findBin.spec.js index fac0c1f3a..0f8dae8fb 100644 --- a/test/findBin.spec.js +++ b/test/findBin.spec.js @@ -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]' + ]) }) }) diff --git a/yarn.lock b/yarn.lock index cd6314d12..175c97ff1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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"