Skip to content

Commit bb01cce

Browse files
alan-agius4Keen Yee Liau
authored and
Keen Yee Liau
committed
feat(@angular-devkit/schematics-cli): add support for camelCase arguments
At the moment, only kebab case args works, and this might be misleading if you come from the Angular CLI. As for instance `--dryRun` will have no effect. Fixes #12599
1 parent 0b4e91b commit bb01cce

File tree

2 files changed

+41
-20
lines changed

2 files changed

+41
-20
lines changed

packages/angular_devkit/schematics_cli/bin/schematics.ts

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,7 @@ export async function main({
6969
stderr = process.stderr,
7070
}: MainOptions): Promise<0 | 1> {
7171

72-
/** Parse the command line. */
73-
const booleanArgs = [
74-
'allowPrivate',
75-
'debug',
76-
'dry-run',
77-
'force',
78-
'help',
79-
'list-schematics',
80-
'verbose',
81-
];
82-
const argv = minimist(args, {
83-
boolean: booleanArgs,
84-
default: {
85-
'debug': null,
86-
'dry-run': null,
87-
},
88-
'--': true,
89-
});
72+
const argv = parseArgs(args);
9073

9174
/** Create the DevKit Logger used through the CLI. */
9275
const logger = createConsoleLogger(argv['verbose'], stdout, stderr);
@@ -128,7 +111,7 @@ export async function main({
128111
const debug: boolean = argv.debug === null ? isLocalCollection : argv.debug;
129112
const dryRun: boolean = argv['dry-run'] === null ? debug : argv['dry-run'];
130113
const force = argv['force'];
131-
const allowPrivate = argv['allowPrivate'];
114+
const allowPrivate = argv['allow-private'];
132115

133116
/** Create a Virtual FS Host scoped to where the process is being run. **/
134117
const fsHost = new virtualFs.ScopedHost(new NodeJsSyncHost(), normalize(process.cwd()));
@@ -282,7 +265,7 @@ function getUsage(): string {
282265
--debug Debug mode. This is true by default if the collection is a relative
283266
path (in that case, turn off with --debug=false).
284267
285-
--allowPrivate Allow private schematics to be run from the command line. Default to
268+
--allow-private Allow private schematics to be run from the command line. Default to
286269
false.
287270
288271
--dry-run Do not output anything, but instead just show what actions would be
@@ -301,6 +284,36 @@ function getUsage(): string {
301284
`;
302285
}
303286

287+
/** Parse the command line. */
288+
const booleanArgs = [
289+
'allowPrivate',
290+
'allow-private',
291+
'debug',
292+
'dry-run',
293+
'dryRun',
294+
'force',
295+
'help',
296+
'list-schematics',
297+
'listSchematics',
298+
'verbose',
299+
];
300+
301+
function parseArgs(args: string[] | undefined): minimist.ParsedArgs {
302+
return minimist(args, {
303+
boolean: booleanArgs,
304+
alias: {
305+
'dryRun': 'dry-run',
306+
'listSchematics': 'list-schematics',
307+
'allowPrivate': 'allow-private',
308+
},
309+
default: {
310+
'debug': null,
311+
'dry-run': null,
312+
},
313+
'--': true,
314+
});
315+
}
316+
304317
if (require.main === module) {
305318
const args = process.argv.slice(2);
306319
main({ args })

packages/angular_devkit/schematics_cli/bin/schematics_spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ describe('schematics-cli binary', () => {
3535
expect(res).toEqual(0);
3636
});
3737

38+
it('listSchematics works', async () => {
39+
const args = ['--listSchematics'];
40+
const res = await main({ args, stdout, stderr });
41+
expect(stdout.lines).toMatch(/blank/);
42+
expect(stdout.lines).toMatch(/schematic/);
43+
expect(res).toEqual(0);
44+
});
45+
3846
it('dry-run works', async () => {
3947
const args = ['blank', 'foo', '--dry-run'];
4048
const res = await main({ args, stdout, stderr });

0 commit comments

Comments
 (0)