Skip to content

Commit

Permalink
fix(@angular/cli): dasherize names option names when using JSON help
Browse files Browse the repository at this point in the history
This ensures that arguments listed in https://angular.io/cli help pages are all in kebab cases.

This is a prerequisite to deprecate camel cased arguments.
  • Loading branch information
alan-agius4 committed Dec 2, 2020
1 parent f0470f8 commit 2a2293c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/angular/cli/models/command.ts
Expand Up @@ -54,7 +54,10 @@ export abstract class Command<T extends BaseCommandOptions = BaseCommandOptions>
}

async printJsonHelp(_options: T & Arguments): Promise<number> {
this.logger.info(JSON.stringify(this.description));
const replacer = (key: string, value: string) => key === 'name'
? strings.dasherize(value)
: value;
this.logger.info(JSON.stringify(this.description, replacer, 2));

return 0;
}
Expand Down
6 changes: 5 additions & 1 deletion tests/legacy-cli/e2e/tests/commands/help/help-json.ts
Expand Up @@ -7,7 +7,11 @@ export default async function() {
const { stdout } = await silentNg(commandName, '--help=json');

if (stdout.trim()) {
JSON.parse(stdout);
JSON.parse(stdout, (key, value) => {
if (key === 'name' && /[A-Z]/.test(value)) {
throw new Error(`Option named '${value}' is not kebab case.`);
}
});
} else {
console.warn(`No JSON output for command [${commandName}].`);
}
Expand Down

0 comments on commit 2a2293c

Please sign in to comment.