Skip to content

Commit 2897d3a

Browse files
committed
fix(@angular/cli): allow command arguments named help
Previously, `localYargs.help('help', ...)` was always enabled regardless of whether `--help` was passed. In Yargs, enabling `.help()` also registers an implicit `help` command/positional trigger, causing commands with a positional argument named `help` (such as `ng generate component help`) to display the CLI help output instead of executing the command. Only enable Yargs help handling when `--help` is present in the parsed options. Fixes #25705
1 parent 88b43b9 commit 2897d3a

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

‎packages/angular/cli/src/command-builder/command-runner.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export async function runCommand(args: string[], logger: logging.Logger): Promis
137137
hidden: true,
138138
type: 'boolean',
139139
})
140-
.help('help', 'Shows a help message for this command in the console.')
140+
.help(help, help ? 'Shows a help message for this command in the console.' : undefined)
141141
// A complete list of strings can be found: https://github.com/yargs/yargs/blob/main/locales/en.json
142142
.updateStrings({
143143
'Commands:': colors.cyan('Commands:'),

‎tests/e2e/tests/generate/component/component-basic.ts‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@ import { join } from 'node:path';
22
import { ng } from '../../../utils/process';
33
import { expectFileToExist } from '../../../utils/fs';
44

5-
export default function () {
6-
const projectDir = join('src', 'app');
7-
const componentDir = join(projectDir, 'test-component');
5+
export default async function () {
6+
const componentDir = 'src/app/test-component';
87

9-
return (
10-
ng('generate', 'component', 'test-component')
11-
.then(() => expectFileToExist(componentDir))
12-
.then(() => expectFileToExist(join(componentDir, 'test-component.ts')))
13-
.then(() => expectFileToExist(join(componentDir, 'test-component.spec.ts')))
14-
.then(() => expectFileToExist(join(componentDir, 'test-component.html')))
15-
.then(() => expectFileToExist(join(componentDir, 'test-component.css')))
8+
await ng('generate', 'component', 'test-component');
9+
await expectFileToExist(componentDir);
10+
await expectFileToExist(join(componentDir, 'test-component.ts'));
11+
await expectFileToExist(join(componentDir, 'test-component.spec.ts'));
12+
await expectFileToExist(join(componentDir, 'test-component.html'));
13+
await expectFileToExist(join(componentDir, 'test-component.css'));
1614

17-
// Try to run the unit tests.
18-
.then(() => ng('test', '--watch=false'))
19-
);
15+
// Try to run the unit tests.
16+
await ng('test', '--watch=false');
17+
18+
// Should generate component that is named "help".
19+
await ng('generate', 'component', 'help');
20+
await expectFileToExist('src/app/help/help.ts');
2021
}

0 commit comments

Comments
 (0)