Skip to content

Commit

Permalink
fix(@angular/cli): schematics commands should fail on unknown options
Browse files Browse the repository at this point in the history
When an addition argument is parsed the schematic commands should fail with an error.

Fixes #12549
  • Loading branch information
alan-agius4 authored and hansl committed Jan 30, 2019
1 parent 0b7ee64 commit f8e873b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/angular/cli/models/schematic-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,15 @@ export abstract class SchematicCommand<
args = await this.parseArguments(schematicOptions || [], o);
}

// ng-add is special because we don't know all possible options at this point
if (args['--'] && schematicName !== 'ng-add') {
args['--'].forEach(additional => {
this.logger.fatal(`Unknown option: '${additional.split(/=/)[0]}'`);
});

return 1;
}

const pathOptions = o ? this.setPathOptions(o, workingDir) : {};
let input = Object.assign(pathOptions, args);

Expand Down
9 changes: 9 additions & 0 deletions tests/legacy-cli/e2e/tests/commands/unknown-option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,13 @@ export default async function() {
[ 'build', '--notanoption' ],
/should NOT have additional properties\(notanoption\)./,
));

const ngGenerateArgs = [ 'generate', 'component', 'component-name', '--notanoption' ];
await expectToFail(() => ng(...ngGenerateArgs));

await execAndWaitForOutputToMatch(
'ng',
ngGenerateArgs,
/Unknown option: '--notanoption'/,
);
}

0 comments on commit f8e873b

Please sign in to comment.