Skip to content

Commit

Permalink
Add aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
gkoberger committed Oct 4, 2016
1 parent bbcaaac commit de9d2c6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions lib/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:");
Expand Down
1 change: 1 addition & 0 deletions lib/try.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 12 additions & 0 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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-')
Expand Down

0 comments on commit de9d2c6

Please sign in to comment.