Skip to content

Commit f15c797

Browse files
committed
fix(@angular/cli): Handle no args and version flag
1 parent 9c17413 commit f15c797

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

packages/@angular/cli/models/command-runner.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export async function runCommand(commandMap: CommandMap,
2727
logger: logging.Logger,
2828
context: CommandContext): Promise<any> {
2929

30+
// if not args supplied, just run the help command.
31+
if (!args || args.length === 0) {
32+
args = ['help'];
33+
}
3034
const rawOptions = yargsParser(args, { alias: { help: ['h'] }, boolean: [ 'help' ] });
3135
let commandName = rawOptions._[0];
3236
// remove the command name
@@ -38,8 +42,7 @@ export async function runCommand(commandMap: CommandMap,
3842
let Cmd: CommandConstructor;
3943
Cmd = findCommand(commandMap, commandName);
4044

41-
const versionAliases = ['-v', '--version'];
42-
if (!Cmd && versionAliases.indexOf(commandName) !== -1) {
45+
if (!Cmd && !commandName && (rawOptions.v || rawOptions.version)) {
4346
commandName = 'version';
4447
Cmd = findCommand(commandMap, commandName);
4548
}
@@ -50,8 +53,9 @@ export async function runCommand(commandMap: CommandMap,
5053
}
5154

5255
if (!Cmd) {
53-
throw new Error(oneLine`The specified command (${commandName}) is invalid.
54-
For available options, see \`ng help\`.`);
56+
logger.error(oneLine`The specified command (${commandName}) is invalid.
57+
For a list of available options, run \`ng help\`.`);
58+
throw '';
5559
}
5660

5761
const command = new Cmd(context, logger);

0 commit comments

Comments
 (0)