Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the Angular CLI command runner to extract initial argument parsing into a separate parseInitialCommandArguments function and adds corresponding unit tests. This change ensures that a bare help argument (e.g., in ng g m help) is not incorrectly treated as a CLI help flag. The feedback suggests a critical improvement: the parser should ignore --help or -h flags if they appear after the -- (double dash) option delimiter, as those should be passed raw to the underlying command. Additionally, a test case should be added to verify this behavior.
| const help = | ||
| jsonHelp || args.some((arg) => arg === '--help' || arg === '-h' || arg.startsWith('--help=')); |
There was a problem hiding this comment.
Checking args.some(...) directly on the raw args array will incorrectly detect --help or -h even if they are specified after the -- (double dash) option delimiter. In CLI tools, arguments after -- are meant to be passed raw to the underlying command/schematic/script and should not be parsed as options for the outer CLI.\n\nFor example, running ng run my-project -- --help or ng test -- --help would incorrectly trigger the global Angular CLI help instead of passing --help to the builder or test runner.\n\nTo fix this, we should only scan the arguments that appear before --.
const dashDashIndex = args.indexOf('--');\n const argsToParse = dashDashIndex === -1 ? args : args.slice(0, dashDashIndex);\n const help =\n jsonHelp || argsToParse.some((arg) => arg === '--help' || arg === '-h' || arg.startsWith('--help='));|
|
||
| expect(help).toBeTrue(); | ||
| expect(positional).toEqual(['generate', 'm']); | ||
| }); |
There was a problem hiding this comment.
It would be beneficial to add a test case to verify that --help is not treated as a help flag when it is passed after the -- delimiter.
});\n\n it('should not treat --help after -- as the help flag', () => {\n const { help } = parseInitialCommandArguments(['run', 'my-project', '--', '--help']);\n\n expect(help).toBeFalse();\n });The initial argv parse treated bare `help` as the global help flag, so commands like `ng generate m help` showed help instead of running the schematic. Fixes angular#25705
852580f to
173b5a6
Compare
|
Thank you for the contribution. Closing this PR because the implementation does not address the actual root cause of #25705: This is being addressed in #34609. |
PR Checklist
PR Type
What is the current behavior?
Issue Number: #25705
Running
ng generate m help(and similar) shows the CLI help menu instead of running the schematic with a positional argument namedhelp.The initial argv parse treated any bare token
helpas the global help flag.What is the new behavior?
Help is detected only from explicit
--help,-h, or--json-help. Positionals namedhelpare passed through to schematics (e.g.ng generate m helpgenerates a module namedhelp).Does this PR introduce a breaking change?
Other information
Fixes #25705
Tests:
pnpm bazel test //packages/angular/cli:test --test_filter="parseInitialCommandArguments"ng generate m help --dry-runin a workspace runs the module schematic instead of printing CLI help