From 9c2a1a525ab551786e4fd08d1fdd6e819960fee8 Mon Sep 17 00:00:00 2001 From: Gregory Koberger Date: Mon, 3 Oct 2016 18:00:08 -0700 Subject: [PATCH] Categorize all options --- api.js | 1 + lib/docs.js | 3 ++- lib/generate.js | 1 + lib/help.js | 35 +++++++++++++++++++++++++++++++---- lib/host.js | 3 ++- lib/init.js | 1 + lib/login.js | 1 + lib/mock.js | 1 + 8 files changed, 40 insertions(+), 6 deletions(-) diff --git a/api.js b/api.js index 9c9427dbe..f586dd9c0 100644 --- a/api.js +++ b/api.js @@ -108,6 +108,7 @@ exports.load = function(action) { console.log('Action not found.'.red); console.log('Type ' + 'api help'.yellow + ' to see all commands'); + process.exit(); }; function exampleId(file, apiId) { diff --git a/lib/docs.js b/lib/docs.js index d4c6710f1..03c1c713e 100644 --- a/lib/docs.js +++ b/lib/docs.js @@ -1,7 +1,8 @@ exports.swagger = true; exports.swaggerUrl = true; exports.login = true; -exports.desc = "Upload your docs to ReadMe.io"; +exports.category = "services"; +exports.desc = "Upload your docs to ReadMe ($)"; exports.run = function(config, info) { console.log('Uploading Swagger file...'); diff --git a/lib/generate.js b/lib/generate.js index 5bab206cf..2fb73ef50 100644 --- a/lib/generate.js +++ b/lib/generate.js @@ -1,6 +1,7 @@ exports.swagger = true; exports.login = false; exports.desc = "Output your Swagger file"; +exports.category = "utility"; exports.run = function(config, info) { console.log(JSON.stringify(info.swagger, undefined, 2)); diff --git a/lib/help.js b/lib/help.js index 10d7a20db..707fa9023 100644 --- a/lib/help.js +++ b/lib/help.js @@ -4,18 +4,45 @@ var _ = require('lodash'); exports.swagger = false; exports.login = false; +exports.category = "basic"; exports.desc = "Learn what you can do with api"; exports.run = function(config, info) { console.log(""); - console.log("Here's a list of what you can do with " + 'api'.yellow + ":"); - console.log(""); + console.log("Usage: api [swagger url]"); var files = glob.sync(path.join(__dirname, "*")); + var categories = { + 'basic': { + desc: 'Commands for getting started', + commands: [], + }, + 'services': { + desc: 'Hosted third-party services ' + '(Will post to the Internet)'.grey, + commands: [], + }, + 'utility': { + desc: 'Utility functions for working locally', + commands: [], + }, + }; + _.each(files, function(file) { var action = file.match(/(\w+).js/)[1]; - var info = require(file).desc || ""; - console.log(" $".grey + pad(" api " + action) + " " + info.grey); + var f = require(file); + var info = f.desc || ""; + + if(f.category) { + categories[f.category].commands.push(" $".grey + pad(" api " + action) + " " + info.grey); + } + }); + + _.each(categories, function(category) { + console.log(""); + console.log(category.desc); + _.each(category.commands, function(command) { + console.log(command); + }); }); console.log(""); diff --git a/lib/host.js b/lib/host.js index fdfed26f4..bc7561c79 100644 --- a/lib/host.js +++ b/lib/host.js @@ -2,10 +2,11 @@ exports.swagger = true; exports.swaggerUrl = true; exports.login = true; exports.desc = "Get a public URL for your API"; +exports.category = "services"; exports.run = function(config, info) { console.log(""); - console.log("Success! ".green + "You can now access your Swagger from the following public URL:"); + console.log("Success! ".green + "You can now access your Swagger from the following publicly sharable URL:"); console.log(""); console.log(" " + info.swaggerUrl); console.log(""); diff --git a/lib/init.js b/lib/init.js index 0dc33780e..6daf27bad 100644 --- a/lib/init.js +++ b/lib/init.js @@ -7,6 +7,7 @@ var utils = require('../utils'); exports.swagger = false; exports.login = false; +exports.category = "basic"; exports.desc = "Create a new API specification"; var types = [ diff --git a/lib/login.js b/lib/login.js index 002bef51c..570f56db6 100644 --- a/lib/login.js +++ b/lib/login.js @@ -4,6 +4,7 @@ var open = require('open'); exports.swagger = false; exports.login = false; exports.desc = "Authenticate this computer"; +exports.category = "utility"; exports.run = function(config, info) { if(info.args[1] == 'info') { diff --git a/lib/mock.js b/lib/mock.js index cf00da5b4..7741edb6e 100644 --- a/lib/mock.js +++ b/lib/mock.js @@ -4,6 +4,7 @@ var request = require('request'); exports.swagger = true; exports.login = true; +exports.category = "services"; exports.desc = "Run a mock server based on your API"; exports.run = function(config, info) {