Skip to content

Commit 6ad093d

Browse files
alan-agius4Angular Builds
authored and
Angular Builds
committed
fix(@angular/cli): schematics commands should fail on unknown options
When an addition argument is parsed the schematic commands should fail with an error. Fixes #12549
1 parent cdcaff8 commit 6ad093d

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

packages/angular/cli/models/schematic-command.ts

+9
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,15 @@ export abstract class SchematicCommand<
437437
args = await this.parseArguments(schematicOptions || [], o);
438438
}
439439

440+
// ng-add is special because we don't know all possible options at this point
441+
if (args['--'] && schematicName !== 'ng-add') {
442+
args['--'].forEach(additional => {
443+
this.logger.fatal(`Unknown option: '${additional.split(/=/)[0]}'`);
444+
});
445+
446+
return 1;
447+
}
448+
440449
const pathOptions = o ? this.setPathOptions(o, workingDir) : {};
441450
let input = Object.assign(pathOptions, args);
442451

tests/legacy-cli/e2e/tests/commands/unknown-option.ts

+9
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,13 @@ export default async function() {
1515
[ 'build', '--notanoption' ],
1616
/should NOT have additional properties\(notanoption\)./,
1717
));
18+
19+
const ngGenerateArgs = [ 'generate', 'component', 'component-name', '--notanoption' ];
20+
await expectToFail(() => ng(...ngGenerateArgs));
21+
22+
await execAndWaitForOutputToMatch(
23+
'ng',
24+
ngGenerateArgs,
25+
/Unknown option: '--notanoption'/,
26+
);
1827
}

0 commit comments

Comments
 (0)