Skip to content

Commit

Permalink
fix(@angular/cli): only add --version option on default command
Browse files Browse the repository at this point in the history
The newly added `--version` option was previously added to all subcommands
which can result in a warning being shown if the subcommand was a builder
or schematics that also happened to have a `version` option. To support
the default `--version` option that displays the actual CLI version, the
option is now only added when no subcommand is present. This prevents
potential version option overlap.

(cherry picked from commit 83ef6a1)
  • Loading branch information
clydin committed May 22, 2024
1 parent 2aeecd6 commit dd786d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
7 changes: 6 additions & 1 deletion packages/angular/cli/src/command-builder/command-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ export async function runCommand(args: string[], logger: logging.Logger): Promis
usageInstance.help = () => jsonHelpUsage();
}

// Add default command to support version option when no subcommand is specified
localYargs.command('*', false, (builder) =>
builder.version('version', 'Show Angular CLI version.', VERSION.full),
);

await localYargs
.scriptName('ng')
// https://github.com/yargs/yargs/blob/main/docs/advanced.md#customizing-yargs-parser
Expand Down Expand Up @@ -123,7 +128,7 @@ export async function runCommand(args: string[], logger: logging.Logger): Promis
.demandCommand(1, demandCommandFailureMessage)
.recommendCommands()
.middleware(normalizeOptionsMiddleware)
.version('version', 'Show Angular CLI version.', VERSION.full)
.version(false)
.showHelpOnFail(false)
.strict()
.fail((msg, err) => {
Expand Down
5 changes: 0 additions & 5 deletions tests/legacy-cli/e2e/tests/commands/help/help-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ export default async function () {
'description': 'If provided, a new value for the given configuration key.',
'positional': 1,
},
{
'name': 'version',
'type': 'boolean',
'description': 'Show Angular CLI version.',
},
],
});

Expand Down

0 comments on commit dd786d4

Please sign in to comment.