Skip to content

Commit 83ef6a1

Browse files
committed
fix(@angular/cli): only add --version option on default command
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.
1 parent d6ea06b commit 83ef6a1

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ export async function runCommand(args: string[], logger: logging.Logger): Promis
9191
usageInstance.help = () => jsonHelpUsage();
9292
}
9393

94+
// Add default command to support version option when no subcommand is specified
95+
localYargs.command('*', false, (builder) =>
96+
builder.version('version', 'Show Angular CLI version.', VERSION.full),
97+
);
98+
9499
await localYargs
95100
.scriptName('ng')
96101
// https://github.com/yargs/yargs/blob/main/docs/advanced.md#customizing-yargs-parser
@@ -123,7 +128,7 @@ export async function runCommand(args: string[], logger: logging.Logger): Promis
123128
.demandCommand(1, demandCommandFailureMessage)
124129
.recommendCommands()
125130
.middleware(normalizeOptionsMiddleware)
126-
.version('version', 'Show Angular CLI version.', VERSION.full)
131+
.version(false)
127132
.showHelpOnFail(false)
128133
.strict()
129134
.fail((msg, err) => {

tests/legacy-cli/e2e/tests/commands/help/help-json.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ export default async function () {
3636
'description': 'If provided, a new value for the given configuration key.',
3737
'positional': 1,
3838
},
39-
{
40-
'name': 'version',
41-
'type': 'boolean',
42-
'description': 'Show Angular CLI version.',
43-
},
4439
],
4540
});
4641

0 commit comments

Comments
 (0)