From 6130427e89e8877a36eaada6515a7bea8dcfb46d Mon Sep 17 00:00:00 2001 From: SamvelRaja Date: Tue, 8 Sep 2015 20:59:49 +0530 Subject: [PATCH] Shows the help if the command is wrong --- lib/cli.js | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index eb3af99..b3fd94c 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -4,14 +4,40 @@ 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' + ]; + +var isSupportedCommands = function(command) { + + for (var i = 0; i < supportedCommands.length; i++) { + if (command === supportedCommands[i]) { + return true; + } + } + + return false; +}; program .version(version); +program + .arguments('') + .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); }); @@ -19,7 +45,7 @@ program 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); }); @@ -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(); + } };