Skip to content

Commit e6350b6

Browse files
committed
fix(@angular-devkit/schematics-cli): correctly parse inline boolean values in CLI options (#34201)
When CLI options defined as boolean are provided with inline values like '--debug=false' or '--dry-run=false', 'node:util.parseArgs' in non-strict mode returns string values ('false' / 'true') rather than booleans. This caused false values to be treated as truthy. Normalize string boolean values in CLI options. Closes #34199 PR Close #34201
1 parent 36d0aab commit e6350b6

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

‎packages/angular_devkit/schematics_cli/bin/schematics.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,15 @@ function parseOptions(args: string[]): Options {
568568
}
569569
}
570570

571+
for (const key of Object.keys(CLI_OPTION_DEFINITIONS)) {
572+
const value = values[key];
573+
if (value === 'true') {
574+
values[key] = true;
575+
} else if (value === 'false') {
576+
values[key] = false;
577+
}
578+
}
579+
571580
return {
572581
_: positionals,
573582
schematicOptions,

‎packages/angular_devkit/schematics_cli/test/schematics_spec.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,33 @@ describe('schematics-cli binary', () => {
5959
expect(res).toEqual(0);
6060
});
6161

62+
it('handles boolean CLI options with explicit inline false values', async () => {
63+
const args = ['blank', 'foo', '--dry-run', '--debug=false'];
64+
const res = await main({ args, stdout, stderr });
65+
const output = stripVTControlCharacters(stdout.read()?.toString() || '');
66+
expect(output).not.toMatch(/Debug mode enabled/);
67+
expect(output).toMatch(/Dry run enabled\./);
68+
expect(res).toEqual(0);
69+
});
70+
71+
it('does not display help when --help=false is passed', async () => {
72+
const args = ['blank', 'foo', '--dry-run', '--help=false'];
73+
const res = await main({ args, stdout, stderr });
74+
const output = stripVTControlCharacters(stdout.read()?.toString() || '');
75+
expect(output).not.toMatch(/schematics \[collection-name:\]schematic-name/);
76+
expect(output).toMatch(/Dry run enabled\./);
77+
expect(res).toEqual(0);
78+
});
79+
80+
it('does not list schematics when --list-schematics=false is passed', async () => {
81+
const args = ['blank', 'foo', '--dry-run', '--list-schematics=false'];
82+
const res = await main({ args, stdout, stderr });
83+
const output = stripVTControlCharacters(stdout.read()?.toString() || '');
84+
expect(output).not.toMatch(/blank/);
85+
expect(output).toMatch(/Dry run enabled\./);
86+
expect(res).toEqual(0);
87+
});
88+
6289
it('error when no name is provided', async () => {
6390
const args = ['blank'];
6491
const res = await main({ args, stdout, stderr });

0 commit comments

Comments
 (0)