Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@angular/cli): support all single dashes prefixed arguments #12783

Merged
merged 1 commit into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/angular/cli/models/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ function _assignOption(
ignored: string[],
errors: string[],
) {
let key = arg.substr(2);
const from = arg.startsWith('--') ? 2 : 1;
let key = arg.substr(from);
let option: Option | null = null;
let value = '';
const i = arg.indexOf('=');
Expand Down Expand Up @@ -172,8 +173,9 @@ function _assignOption(
value = arg.substring(i + 1);
}
}

if (option === null) {
if (args[0] && !args[0].startsWith('--')) {
if (args[0] && !args[0].startsWith('-')) {
leftovers.push(arg, args[0]);
args.shift();
} else {
Expand Down Expand Up @@ -285,14 +287,14 @@ export function parseArguments(args: string[], options: Option[] | null): Argume
const flag = arg[i];
// If the next character is an '=', treat it as a long flag.
if (arg[i + 1] == '=') {
const f = '--' + flag + arg.slice(i + 1);
const f = '-' + flag + arg.slice(i + 1);
_assignOption(f, args, options, parsedOptions, positionals, leftovers, ignored, errors);
break;
}
// Treat the last flag as `--a` (as if full flag but just one letter). We do this in
// the loop because it saves us a check to see if the arg is just `-`.
if (i == arg.length - 1) {
const arg = '--' + flag;
const arg = '-' + flag;
_assignOption(arg, args, options, parsedOptions, positionals, leftovers, ignored, errors);
} else {
const maybeOption = _getOptionFromName(flag, options);
Expand Down
8 changes: 8 additions & 0 deletions packages/angular/cli/models/parser_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ describe('parseArguments', () => {
'--e3 true': { e3: true },
'--e3=true': { e3: true },
'a b c 1': { p1: 'a', p2: 'b', '--': ['c', '1'] },

'-p=1 -c=prod': {'--': ['-p=1', '-c=prod'] },
alan-agius4 marked this conversation as resolved.
Show resolved Hide resolved
'--p --c': {'--': ['--p', '--c'] },
'--p=123': {'--': ['--p=123'] },
'--p -c': {'--': ['--p', '-c'] },
'-p --c': {'--': ['-p', '--c'] },
'-p --c 123': {'--': ['-p', '--c', '123'] },
'--c 123 -p': {'--': ['--c', '123', '-p'] },
};

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