Skip to content

Commit

Permalink
Add external command support for commands on any level
Browse files Browse the repository at this point in the history
  • Loading branch information
arikon committed Jul 10, 2013
1 parent 2dde9d1 commit 15c6a11
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
14 changes: 12 additions & 2 deletions lib/cmd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion src/cmd.coffee
Expand Up @@ -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
# <command>-<subcommand>-<subcommand> 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
Expand Down
13 changes: 13 additions & 0 deletions test/coa.js
Expand Up @@ -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()');
Expand Down

0 comments on commit 15c6a11

Please sign in to comment.