Skip to content

Commit fc33e5f

Browse files
committed
fix(@angular/cli): dasherize names option names when using JSON help
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. (cherry picked from commit 7aa9bba)
1 parent 917cca8 commit fc33e5f

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/angular/cli/models/command.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ export abstract class Command<T extends BaseCommandOptions = BaseCommandOptions>
5454
}
5555

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

5962
return 0;
6063
}

tests/legacy-cli/e2e/tests/commands/help/help-json.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ export default async function() {
77
const { stdout } = await silentNg(commandName, '--help=json');
88

99
if (stdout.trim()) {
10-
JSON.parse(stdout);
10+
JSON.parse(stdout, (key, value) => {
11+
if (key === 'name' && /[A-Z]/.test(value)) {
12+
throw new Error(`Option named '${value}' is not kebab case.`);
13+
}
14+
});
1115
} else {
1216
console.warn(`No JSON output for command [${commandName}].`);
1317
}

0 commit comments

Comments
 (0)