@@ -14,6 +14,23 @@ const Store = require('./store');
14
14
const resolver = require ( './resolver' ) ;
15
15
const TerminalAdapter = require ( './adapter' ) ;
16
16
17
+ /**
18
+ * Two-step argument splitting function that first splits arguments in quotes,
19
+ * and then splits up the remaining arguments if they are not part of a quote.
20
+ */
21
+ function splitArgsFromString ( argsString ) {
22
+ let result = [ ] ;
23
+ const quoteSeparatedArgs = argsString . split ( / ( \x22 [ ^ \x22 ] * \x22 ) / ) . filter ( x => x ) ;
24
+ quoteSeparatedArgs . forEach ( arg => {
25
+ if ( arg . match ( '\x22' ) ) {
26
+ result . push ( arg . replace ( / \x22 / g, '' ) ) ;
27
+ } else {
28
+ result = result . concat ( arg . trim ( ) . split ( ' ' ) ) ;
29
+ }
30
+ } ) ;
31
+ return result ;
32
+ }
33
+
17
34
/**
18
35
* `Environment` object is responsible of handling the lifecyle and bootstrap
19
36
* of generators in a specific environment (your app).
@@ -107,7 +124,7 @@ class Environment extends EventEmitter {
107
124
super ( ) ;
108
125
109
126
args = args || [ ] ;
110
- this . arguments = Array . isArray ( args ) ? args : args . split ( ' ' ) ;
127
+ this . arguments = Array . isArray ( args ) ? args : splitArgsFromString ( args ) ;
111
128
this . options = opts || { } ;
112
129
this . adapter = adapter || new TerminalAdapter ( ) ;
113
130
this . cwd = this . options . cwd || process . cwd ( ) ;
@@ -376,7 +393,7 @@ class Environment extends EventEmitter {
376
393
options = options || { } ;
377
394
378
395
let args = options . arguments || options . args || _ . clone ( this . arguments ) ;
379
- args = Array . isArray ( args ) ? args : args . split ( ' ' ) ;
396
+ args = Array . isArray ( args ) ? args : splitArgsFromString ( args ) ;
380
397
381
398
const opts = options . options || _ . clone ( this . options ) ;
382
399
@@ -410,7 +427,7 @@ class Environment extends EventEmitter {
410
427
args = this . arguments ;
411
428
}
412
429
413
- args = Array . isArray ( args ) ? args : args . split ( ' ' ) ;
430
+ args = Array . isArray ( args ) ? args : splitArgsFromString ( args ) ;
414
431
options = options || this . options ;
415
432
416
433
const name = args . shift ( ) ;
0 commit comments