Skip to content

Commit

Permalink
Adding support for yogi subcommands
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Dec 5, 2012
1 parent 0196bb3 commit 9b21d18
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
42 changes: 31 additions & 11 deletions bin/yogi.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ http://yuilibrary.com/license/
var log = require('../lib/log'); var log = require('../lib/log');
var config = require('../lib/config'); var config = require('../lib/config');
var args = require('../lib/args'); var args = require('../lib/args');

var which = require('which');
var spawn = require('win-spawn');
var path = require('path');


var options = args.parse(); var options = args.parse();
config.init(options); config.init(options);
Expand All @@ -22,17 +24,35 @@ log.debug('starting up yogi');
log.debug("I'm smarter than the av-er-age bear!"); log.debug("I'm smarter than the av-er-age bear!");


if (!options.cmd) { if (!options.cmd) {
log.bail('Command not known: ' + options.main); var external;
}
try {
external = which.sync('yogi-' + options.main);
} catch (e) {
}
if (external) {
log.debug('executing external command: ' + external);
var env = process.env;
env.YOGI_PATH = path.join(__dirname, '../');

external = spawn(external, process.argv.splice(3), {
cwd: process.cwd(),
env: env,
stdio: 'inherit'
});
} else {
log.bail('Command not known: ' + options.main);
}


var cmd = options.cmd; } else {
var cmd = options.cmd;


if (cmd.init) { if (cmd.init) {
cmd.init(options); cmd.init(options);
if (cmd.run) { if (cmd.run) {
cmd.run(); cmd.run();
}
} else if (Array.isArray(cmd)) {
log.info('available commands: ' + cmd.join(' '));
} }
} else if (Array.isArray(cmd)) {
log.info('available commands: ' + cmd.join(' '));
} }

3 changes: 2 additions & 1 deletion package.json
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"wiky.js": "https://github.com/davglass/wiky.js/tarball/master", "wiky.js": "https://github.com/davglass/wiky.js/tarball/master",
"timethat": "*", "timethat": "*",
"git-travis": "~0.1.2", "git-travis": "~0.1.2",
"win-spawn": "*" "win-spawn": "*",
"which": "*"
}, },
"scripts": { "scripts": {
"pretest": "jshint --config ./node_modules/yui-lint/jshint.json ./lib/*.js ./lib/*/*.js", "pretest": "jshint --config ./node_modules/yui-lint/jshint.json ./lib/*.js ./lib/*/*.js",
Expand Down
9 changes: 0 additions & 9 deletions tests/args.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -71,15 +71,6 @@ var tests = {
assert.equal(topic.parsed.loglevel, 'silent'); assert.equal(topic.parsed.loglevel, 'silent');
} }
}, },
'should parse --json <path>': {
topic: function() {
return args.parse(['', '', '--json', './some/path']);
},
'should parse': function(topic) {
assert.equal(topic.main, 'help');
assert.equal(topic.parsed.json, path.normalize(path.resolve('./some/path')));
}
},
'should parse --json': { 'should parse --json': {
topic: function() { topic: function() {
return args.parse(['', '', '--json']); return args.parse(['', '', '--json']);
Expand Down

0 comments on commit 9b21d18

Please sign in to comment.