Skip to content

fix(@angular/cli): allow schematic arguments named help - #34596

Closed
ant1quar wants to merge 1 commit into
angular:mainfrom
ant1quar:fix/25705-generate-help-name
Closed

ant1quar wants to merge 1 commit into
angular:mainfrom
ant1quar:fix/25705-generate-help-name

Conversation

@ant1quar

@ant1quar ant1quar commented Oct 29, 2026 •

Copy link
Copy Markdown

PR Checklist

PR Type

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

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 named help.

The initial argv parse treated any bare token help as the global help flag.

What is the new behavior?

Help is detected only from explicit --help, -h, or --json-help. Positionals named help are passed through to schematics (e.g. ng generate m help generates a module named help).

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Fixes #25705

Tests:

  • pnpm bazel test //packages/angular/cli:test --test_filter="parseInitialCommandArguments"
  • Manual: ng generate m help --dry-run in a workspace runs the module schematic instead of printing CLI help

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +50 to +51
const help =
jsonHelp || args.some((arg) => arg === '--help' || arg === '-h' || arg.startsWith('--help='));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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']);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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
@ant1quar
ant1quar force-pushed the fix/25705-generate-help-name branch from 852580f to 173b5a6 Compare October 30, 2026 13:07
@alan-agius4 alan-agius4 self-assigned this Oct 30, 2026
@alan-agius4

Copy link
Copy Markdown
Collaborator

Thank you for the contribution. Closing this PR because the implementation does not address the actual root cause of #25705: yargsParser does not treat a bare help positional token as the --help boolean option. Instead, the issue occurs because calling localYargs.help('help', ...) unconditionally in Yargs also registers an implicit help command/positional trigger.

This is being addressed in #34609.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ng generate m help does not generate module but shows help menu

2 participants

⌂ Proxy