Skip to content

fix(@angular/cli): schematics commands should fail on unknown options #13480

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

Merged
merged 1 commit into from
Jan 30, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing schematicName == ng-add why not use a this.validateAdditionalArgs() or maybe a allowAdditionalArgs getter that is false for the base command class, true for add?

People can still ng generate something:ng-add and it would trigger this condition.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will follow up on this as I like the idea.

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'/,
);
}