Skip to content

Commit

Permalink
Merge pull request tj#502 from bkendall/fix-sub-sub-commands
Browse files Browse the repository at this point in the history
Fix Sub-Subcommands
  • Loading branch information
SomeKittens committed Feb 11, 2016
2 parents 920dc87 + 33751b4 commit c3ca1f6
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
var proc;
if (process.platform !== 'win32') {
if (isExplicitJS) {
args.unshift(localBin);
args.unshift(bin);
// add executable arguments to spawn
args = (process.execArgv || []).concat(args);

Expand All @@ -534,7 +534,7 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
proc = spawn(bin, args, { stdio: 'inherit', customFds: [0, 1, 2] });
}
} else {
args.unshift(localBin);
args.unshift(bin);
proc = spawn(process.execPath, args, { stdio: 'inherit'});
}

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ program
.version('0.0.1')
.command('install [name]', 'install one or more packages')
.command('search [query]', 'search with optional query')
.command('cache', 'actions dealing with the cache')
.command('list', 'list packages installed')
.command('publish', 'publish or update package')
.command('default', 'default command', {noHelp: true, isDefault: true})
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/pm-cache-clear.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('cache-clear')
1 change: 1 addition & 0 deletions test/fixtures/pm-cache-validate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('cache-validate')
6 changes: 6 additions & 0 deletions test/fixtures/pm-cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var program = require('../../');

program
.command('clear', 'clear the cache')
.command('validate', 'validate the cache', { isDefault: true })
.parse(process.argv);
32 changes: 32 additions & 0 deletions test/test.command.executableSubcommandSubCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var exec = require('child_process').exec
, path = require('path')
, should = require('should');


/*
* The commands look like this
* pm cache
* pm cache clear
* pm cache validate (default)
*/

var bin = path.join(__dirname, './fixtures/pm')
// should list commands at top-level sub command
exec(bin + ' cache help', function (error, stdout, stderr) {
stdout.should.containEql('Usage:');
stdout.should.containEql('cache');
stdout.should.containEql('validate');
});

// should run sub-subcommand
exec(bin + ' cache clear', function (error, stdout, stderr) {
stdout.should.equal('cache-clear\n');
stderr.should.equal('');
});

// should print the default command when passed invalid sub-subcommand
exec(bin + ' cache nope', function (error, stdout, stderr) {
stdout.should.equal('cache-validate\n');
stderr.should.equal('');
});

0 comments on commit c3ca1f6

Please sign in to comment.