Skip to content

Commit

Permalink
instantiate command class if it inherits BaseCommand class
Browse files Browse the repository at this point in the history
  • Loading branch information
voxsim committed Mar 7, 2017
1 parent f4b47ae commit 9ba40d2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/cli/commands/_base.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* @flow */

export default class BaseCommand {
static hasWrapper(): boolean {
hasWrapper(): boolean {
return true;
}
}
4 changes: 2 additions & 2 deletions src/cli/commands/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {sortAlpha, hyphenate} from '../../util/misc.js';
const chalk = require('chalk');

export default class HelpCommand extends BaseCommand {
static hasWrapper(): boolean {
hasWrapper(): boolean {
return false;
}

static run(
run(
config: Config,
reporter: Reporter,
commander: Object,
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import * as tag from './tag.js'; export {tag};
import * as team from './team.js'; export {team};
import * as unlink from './unlink.js'; export {unlink};
import * as upgrade from './upgrade.js'; export {upgrade};
import * as upgradeInteractive from './upgrade-interactive.js'; export {upgradeInteractive};
import * as version from './version.js'; export {version};
import * as versions from './versions.js'; export {versions};
import * as why from './why.js'; export {why};
import * as upgradeInteractive from './upgrade-interactive.js'; export {upgradeInteractive};

import buildUseless from './_useless.js';

Expand Down
5 changes: 5 additions & 0 deletions src/cli/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow */

import BaseCommand from './commands/_base.js';
import {ConsoleReporter, JSONReporter} from '../reporters/index.js';
import {registries, registryNames} from '../registries/index.js';
import * as commands from './commands/index.js';
Expand Down Expand Up @@ -127,6 +128,9 @@ if (!command) {
const camelised = camelCase(commandName);
if (camelised) {
command = commands[camelised];
if (command && command.prototype instanceof BaseCommand) {
command = new command();
}
}
}

Expand Down Expand Up @@ -168,6 +172,7 @@ if (command) {
} else {
command = commands.run;
}

invariant(command, 'missing command');

//
Expand Down

0 comments on commit 9ba40d2

Please sign in to comment.