Skip to content

Commit

Permalink
Shows the help if the command is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
SamvelRaja committed Sep 8, 2015
1 parent 0d2499c commit ca911f0
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,48 @@ var program = require('commander');
var Watson = require('./watson');
var watson = new Watson();
var version = require('../package.json').version;
var supportedCommands = ['upgrade-qunit-tests', 'convert-prototype-extensions',
'convert-prototype-extensions', 'convert-ember-data-model-lookups',
'convert-ember-data-async-false-relationships', 'convert-resource-router-mapping',
'methodify', 'find-overloaded-cps'
];

function isSupportedCommands(command) {

for (var i = 0; i < supportedCommands.length; i++) {
if (command === supportedCommands[i]) {
return true;
}
}

return false;
};

program
.version(version);

program
.arguments('<cmd>')
.action(function(cmd) {
if (!isSupportedCommands(cmd)) {
console.error('The command is not supported, Use the below supported commands');
program.outputHelp();
process.exit(1);
}
});

program
.command('upgrade-qunit-tests [testsPath]')
.description('Fix QUnit tests to match 2.0 syntax. testsPath defaults to tests/')
.action(function(testsPath){
.action(function(testsPath) {
testsPath = testsPath || 'tests';
watson.transformQUnitTest(testsPath);
});

program
.command('convert-prototype-extensions [appPath]')
.description('Convert computed properties and observers to not use prototype extensions. appPath defaults to app/')
.action(function(appPath){
.action(function(appPath) {
appPath = appPath || 'app';
watson.transformPrototypeExtensions(appPath);
});
Expand Down Expand Up @@ -65,7 +91,9 @@ program
watson.findOverloadedCPs(path).outputSummary(options.json ? 'json' : 'pretty');
});


module.exports = function init(args) {
program.parse(args);
if (!process.argv.slice(2).length) {
program.outputHelp();
}
};

0 comments on commit ca911f0

Please sign in to comment.