From de9d2c69e5720986d6f70bc093ff9a3e4ecad146 Mon Sep 17 00:00:00 2001 From: Gregory Koberger Date: Mon, 3 Oct 2016 19:05:21 -0700 Subject: [PATCH] Add aliases --- api.js | 8 ++++++++ lib/docs.js | 1 + lib/try.js | 1 + utils.js | 12 ++++++++++++ 4 files changed, 22 insertions(+) diff --git a/api.js b/api.js index d4eaa36dd..9f9db4428 100644 --- a/api.js +++ b/api.js @@ -95,11 +95,19 @@ exports.api = function(args, opts) { }; exports.load = function(action) { + if(!action) action = 'help'; + var file = path.join(__dirname, 'lib', `${action}.js`); if(utils.fileExists(file)) { return require(file); } + var alias = utils.getAliasFile(action); + if(alias) { + var file = path.join(__dirname, 'lib', `${alias}.js`); + return require(file); + } + console.log('Action not found.'.red); console.log('Type ' + 'api help'.yellow + ' to see all commands'); process.exit(); diff --git a/lib/docs.js b/lib/docs.js index 5665854b2..3ef7ec40b 100644 --- a/lib/docs.js +++ b/lib/docs.js @@ -3,6 +3,7 @@ exports.swaggerUrl = true; exports.login = true; exports.category = "services"; exports.desc = "Upload your docs to ReadMe ($)"; +exports.aliases = ['documentation', 'readme', 'readme.io', 'readmeio']; exports.run = function(config, info) { console.log("You can view your new docs here:"); diff --git a/lib/try.js b/lib/try.js index b08ba11c5..fb488a93f 100644 --- a/lib/try.js +++ b/lib/try.js @@ -3,6 +3,7 @@ var Swagger2Postman = require('swagger2-to-postman'); exports.swagger = true; exports.category = "services"; exports.desc = "Open your Swagger file in Postman ($)"; +exports.aliases = ['postman']; exports.run = function(config, info) { var swaggerConverter = new Swagger2Postman(); diff --git a/utils.js b/utils.js index 6bb2832a4..3dea1a2b6 100644 --- a/utils.js +++ b/utils.js @@ -60,6 +60,18 @@ exports.findSwagger = function(cb, opts) { }; +exports.getAliasFile = function(unknownAction) { + var files = glob.sync(path.join(__dirname, "lib", "*")); + var foundAction = false; + _.each(files, function(file) { + var actionInfo = require(file); + if(actionInfo.aliases && actionInfo.aliases.indexOf(unknownAction) >= 0) { + foundAction = file.match(/(\w+).js/)[1]; + } + }); + return foundAction; +}; + exports.removeMetadata = function(obj) { for(prop in obj) { if (prop.substr(0, 5) === 'x-si-')