diff --git a/lib/cmd.js b/lib/cmd.js index 6320f2f..7e6426a 100644 --- a/lib/cmd.js +++ b/lib/cmd.js @@ -307,7 +307,7 @@ exports.Cmd = Cmd = (function() { }; Cmd.prototype._parseCmd = function(argv, unparsed) { - var cmd, cmdDesc, e, i, optSeen; + var c, cmd, cmdDesc, e, i, optSeen, pkg; if (unparsed == null) { unparsed = []; } @@ -320,8 +320,18 @@ exports.Cmd = Cmd = (function() { if (!optSeen && /^\w[\w-_]*$/.test(i)) { cmd = this._cmdsByName[i]; if (!cmd) { + pkg = ''; + c = this; + while (true) { + pkg = c._name + '-' + pkg; + if (c._cmd === c) { + break; + } + c = c._cmd; + } + console.log(pkg); try { - cmdDesc = require(this._name + '-' + i); + cmdDesc = require(pkg + i); } catch (_error) { e = _error; } diff --git a/src/cmd.coffee b/src/cmd.coffee index e3e6985..805b12d 100644 --- a/src/cmd.coffee +++ b/src/cmd.coffee @@ -238,8 +238,18 @@ exports.Cmd = class Cmd if not optSeen and /^\w[\w-_]*$/.test(i) cmd = @_cmdsByName[i] if not cmd + + # construct package name to require + # -- and so on + pkg = '' + c = @ + loop + pkg = c._name + '-' + pkg + if c._cmd == c then break + c = c._cmd + try - cmdDesc = require(@_name + '-' + i) + cmdDesc = require(pkg + i) catch e if cmdDesc diff --git a/test/coa.js b/test/coa.js index 14efe32..f962ffb 100644 --- a/test/coa.js +++ b/test/coa.js @@ -435,6 +435,19 @@ describe('Cmd', function() { }); }); + describe('2nd level subcommand', function() { + var cmd = COA.Cmd() + .name('coa') + .cmd() + .name('test') + .end(); + + it('should be invoked and accept passed opts and args', function() { + return cmd.do(['test', 'obj', '--opt', 'value', 'value', 'value 1', 'value 2']) + .then(doTest); + }); + }); + }); it('helpful(), name(), title()');