Comparing version 1.1.0 to 1.1.1
@@ -0,1 +1,2 @@ | ||
import debug from 'debug'; | ||
import minimist from 'minimist'; | ||
@@ -23,5 +24,10 @@ | ||
exports.__esModule = true; | ||
var cmdDebug = debug('storbi:command'); | ||
var processArgs = function () { | ||
var inArgs = minimist(process.argv.slice(2)); | ||
cmdDebug('Runtime args: %O', inArgs); | ||
var _a = inArgs._, command = _a[0], subcommand = _a[1], rest = _a.slice(2); | ||
cmdDebug('Command: %s', command); | ||
cmdDebug('Sub Command: %s', subcommand); | ||
cmdDebug('Rest args %O', rest); | ||
var outArgs = { command: command, subcommand: subcommand }; | ||
@@ -37,2 +43,3 @@ if (rest.length > 0) { | ||
this.args = processArgs(); | ||
cmdDebug('Processed args: %O', this.args); | ||
} | ||
@@ -73,4 +80,6 @@ return BaseCommand; | ||
exports.__esModule = true; | ||
var cliDebug = debug('storbi:cli'); | ||
var parseCommands = function (cmds) { | ||
var returnCommands = {}; | ||
cliDebug('Received Commands: %O', cmds); | ||
if (!(cmds instanceof Array)) { | ||
@@ -83,2 +92,3 @@ cmds = [cmds]; | ||
var cmd = new CMD(); | ||
cliDebug('Constructing Command: %s', cmd.name); | ||
returnCommands[cmd.name] = cmd; | ||
@@ -91,9 +101,18 @@ }); | ||
this.commands = parseCommands(cmds); | ||
if (debug.enabled) { | ||
Object.keys(this.commands).forEach(function (command) { | ||
return cliDebug('Loaded Command: %s', command); | ||
}); | ||
} | ||
} | ||
CLI.prototype.run = function () { | ||
var cmd = minimist(process.argv.slice(2))._[0]; | ||
cliDebug('Attempting to run command: %s', cmd); | ||
try { | ||
this.commands[cmd].run(); | ||
var command = this.commands[cmd]; | ||
cliDebug('Found command %s, calling run()', cmd); | ||
command.run(); | ||
} | ||
catch (error) { | ||
cliDebug('Did not find command %s, running help', cmd); | ||
this.commands.defaulthelp.run(); | ||
@@ -105,5 +124,8 @@ } | ||
exports["default"] = CLI; | ||
exports.BaseCommand = baseCommand["default"]; | ||
}); | ||
var index = unwrapExports(src); | ||
var src_1 = src.BaseCommand; | ||
export default index; | ||
export { src_1 as BaseCommand }; |
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var debug = _interopDefault(require('debug')); | ||
var minimist = _interopDefault(require('minimist')); | ||
@@ -27,5 +30,10 @@ | ||
exports.__esModule = true; | ||
var cmdDebug = debug('storbi:command'); | ||
var processArgs = function () { | ||
var inArgs = minimist(process.argv.slice(2)); | ||
cmdDebug('Runtime args: %O', inArgs); | ||
var _a = inArgs._, command = _a[0], subcommand = _a[1], rest = _a.slice(2); | ||
cmdDebug('Command: %s', command); | ||
cmdDebug('Sub Command: %s', subcommand); | ||
cmdDebug('Rest args %O', rest); | ||
var outArgs = { command: command, subcommand: subcommand }; | ||
@@ -41,2 +49,3 @@ if (rest.length > 0) { | ||
this.args = processArgs(); | ||
cmdDebug('Processed args: %O', this.args); | ||
} | ||
@@ -77,4 +86,6 @@ return BaseCommand; | ||
exports.__esModule = true; | ||
var cliDebug = debug('storbi:cli'); | ||
var parseCommands = function (cmds) { | ||
var returnCommands = {}; | ||
cliDebug('Received Commands: %O', cmds); | ||
if (!(cmds instanceof Array)) { | ||
@@ -87,2 +98,3 @@ cmds = [cmds]; | ||
var cmd = new CMD(); | ||
cliDebug('Constructing Command: %s', cmd.name); | ||
returnCommands[cmd.name] = cmd; | ||
@@ -95,9 +107,18 @@ }); | ||
this.commands = parseCommands(cmds); | ||
if (debug.enabled) { | ||
Object.keys(this.commands).forEach(function (command) { | ||
return cliDebug('Loaded Command: %s', command); | ||
}); | ||
} | ||
} | ||
CLI.prototype.run = function () { | ||
var cmd = minimist(process.argv.slice(2))._[0]; | ||
cliDebug('Attempting to run command: %s', cmd); | ||
try { | ||
this.commands[cmd].run(); | ||
var command = this.commands[cmd]; | ||
cliDebug('Found command %s, calling run()', cmd); | ||
command.run(); | ||
} | ||
catch (error) { | ||
cliDebug('Did not find command %s, running help', cmd); | ||
this.commands.defaulthelp.run(); | ||
@@ -109,5 +130,8 @@ } | ||
exports["default"] = CLI; | ||
exports.BaseCommand = baseCommand["default"]; | ||
}); | ||
var index = unwrapExports(src); | ||
var src_1 = src.BaseCommand; | ||
module.exports = index; | ||
exports.default = index; | ||
exports.BaseCommand = src_1; |
@@ -16,1 +16,2 @@ export interface Constructable<T> { | ||
} | ||
export { default as BaseCommand } from './baseCommand'; |
{ | ||
"name": "storbi", | ||
"description": "An opinionated CLI application framework", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"main": "dist/index.js", | ||
@@ -28,5 +28,7 @@ "module": "dist/index.es.js", | ||
"dependencies": { | ||
"debug": "^3.1.0", | ||
"minimist": "^1.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/debug": "^0.0.30", | ||
"@types/jest": "^22.2.0", | ||
@@ -33,0 +35,0 @@ "@types/minimist": "^1.2.0", |
@@ -0,3 +1,6 @@ | ||
import * as debug from 'debug' | ||
import * as minimist from 'minimist' | ||
const cmdDebug = debug('storbi:command') | ||
export interface CommandArgs { | ||
@@ -9,4 +12,9 @@ [argName: string]: string | boolean | string[] | ||
const inArgs = minimist(process.argv.slice(2)) | ||
cmdDebug('Runtime args: %O', inArgs) | ||
const [command, subcommand, ...rest] = inArgs._ | ||
cmdDebug('Command: %s', command) | ||
cmdDebug('Sub Command: %s', subcommand) | ||
cmdDebug('Rest args %O', rest) | ||
const outArgs: CommandArgs = { command, subcommand } | ||
@@ -29,3 +37,5 @@ | ||
this.args = processArgs() | ||
cmdDebug('Processed args: %O', this.args) | ||
} | ||
} |
@@ -0,4 +1,7 @@ | ||
import * as debug from 'debug' | ||
import * as minimist from 'minimist' | ||
import Help from './helpCommand' | ||
const cliDebug = debug('storbi:cli') | ||
export interface Constructable<T> { | ||
@@ -22,2 +25,4 @@ new (): T | ||
cliDebug('Received Commands: %O', cmds) | ||
if (!(cmds instanceof Array)) { | ||
@@ -33,2 +38,3 @@ cmds = [cmds] | ||
const cmd = new CMD() | ||
cliDebug('Constructing Command: %s', cmd.name) | ||
returnCommands[cmd.name] = cmd | ||
@@ -45,2 +51,7 @@ }) | ||
this.commands = parseCommands(cmds) | ||
if (debug.enabled) { | ||
Object.keys(this.commands).forEach(command => | ||
cliDebug('Loaded Command: %s', command) | ||
) | ||
} | ||
} | ||
@@ -51,5 +62,10 @@ | ||
cliDebug('Attempting to run command: %s', cmd) | ||
try { | ||
this.commands[cmd].run() | ||
const command = this.commands[cmd] | ||
cliDebug('Found command %s, calling run()', cmd) | ||
command.run() | ||
} catch (error) { | ||
cliDebug('Did not find command %s, running help', cmd) | ||
this.commands.defaulthelp.run() | ||
@@ -59,1 +75,3 @@ } | ||
} | ||
export { default as BaseCommand } from './baseCommand' |
Sorry, the diff of this file is not supported yet
212652
516
2
26
+ Addeddebug@^3.1.0
+ Addeddebug@3.2.7(transitive)
+ Addedms@2.1.3(transitive)