Skip to content

Commit

Permalink
fix(@angular/cli): Handle no args and version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Brocco committed Mar 9, 2018
1 parent 9c17413 commit f15c797
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/@angular/cli/models/command-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export async function runCommand(commandMap: CommandMap,
logger: logging.Logger,
context: CommandContext): Promise<any> {

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

const versionAliases = ['-v', '--version'];
if (!Cmd && versionAliases.indexOf(commandName) !== -1) {
if (!Cmd && !commandName && (rawOptions.v || rawOptions.version)) {
commandName = 'version';
Cmd = findCommand(commandMap, commandName);
}
Expand All @@ -50,8 +53,9 @@ export async function runCommand(commandMap: CommandMap,
}

if (!Cmd) {
throw new Error(oneLine`The specified command (${commandName}) is invalid.
For available options, see \`ng help\`.`);
logger.error(oneLine`The specified command (${commandName}) is invalid.
For a list of available options, run \`ng help\`.`);
throw '';
}

const command = new Cmd(context, logger);
Expand Down

0 comments on commit f15c797

Please sign in to comment.