Skip to content

Commit ebd2453

Browse files
alan-agius4vikerman
authored andcommittedNov 7, 2018
fix(@angular/cli): support all single dashes prefixed arguments (#12783)
Fixes #12771
1 parent 53dcd37 commit ebd2453

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed
 

‎packages/angular/cli/models/parser.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ function _assignOption(
119119
ignored: string[],
120120
errors: string[],
121121
) {
122-
let key = arg.substr(2);
122+
const from = arg.startsWith('--') ? 2 : 1;
123+
let key = arg.substr(from);
123124
let option: Option | null = null;
124125
let value = '';
125126
const i = arg.indexOf('=');
@@ -172,8 +173,9 @@ function _assignOption(
172173
value = arg.substring(i + 1);
173174
}
174175
}
176+
175177
if (option === null) {
176-
if (args[0] && !args[0].startsWith('--')) {
178+
if (args[0] && !args[0].startsWith('-')) {
177179
leftovers.push(arg, args[0]);
178180
args.shift();
179181
} else {
@@ -285,14 +287,14 @@ export function parseArguments(args: string[], options: Option[] | null): Argume
285287
const flag = arg[i];
286288
// If the next character is an '=', treat it as a long flag.
287289
if (arg[i + 1] == '=') {
288-
const f = '--' + flag + arg.slice(i + 1);
290+
const f = '-' + flag + arg.slice(i + 1);
289291
_assignOption(f, args, options, parsedOptions, positionals, leftovers, ignored, errors);
290292
break;
291293
}
292294
// Treat the last flag as `--a` (as if full flag but just one letter). We do this in
293295
// the loop because it saves us a check to see if the arg is just `-`.
294296
if (i == arg.length - 1) {
295-
const arg = '--' + flag;
297+
const arg = '-' + flag;
296298
_assignOption(arg, args, options, parsedOptions, positionals, leftovers, ignored, errors);
297299
} else {
298300
const maybeOption = _getOptionFromName(flag, options);

‎packages/angular/cli/models/parser_spec.ts

+8
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ describe('parseArguments', () => {
128128
'--e3 true': { e3: true },
129129
'--e3=true': { e3: true },
130130
'a b c 1': { p1: 'a', p2: 'b', '--': ['c', '1'] },
131+
132+
'-p=1 -c=prod': {'--': ['-p=1', '-c=prod'] },
133+
'--p --c': {'--': ['--p', '--c'] },
134+
'--p=123': {'--': ['--p=123'] },
135+
'--p -c': {'--': ['--p', '-c'] },
136+
'-p --c': {'--': ['-p', '--c'] },
137+
'-p --c 123': {'--': ['-p', '--c', '123'] },
138+
'--c 123 -p': {'--': ['--c', '123', '-p'] },
131139
};
132140

133141
Object.entries(tests).forEach(([str, expected]) => {

0 commit comments

Comments
 (0)