diff --git a/bin/yogi.js b/bin/yogi.js index 619959a..4e2e9f1 100755 --- a/bin/yogi.js +++ b/bin/yogi.js @@ -9,7 +9,9 @@ http://yuilibrary.com/license/ var log = require('../lib/log'); var config = require('../lib/config'); var args = require('../lib/args'); - +var which = require('which'); +var spawn = require('win-spawn'); +var path = require('path'); var options = args.parse(); config.init(options); @@ -22,17 +24,35 @@ log.debug('starting up yogi'); log.debug("I'm smarter than the av-er-age bear!"); 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) { - cmd.init(options); - if (cmd.run) { - cmd.run(); + if (cmd.init) { + cmd.init(options); + if (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(' ')); } - diff --git a/package.json b/package.json index 7373e5e..9b0fb2a 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,8 @@ "wiky.js": "https://github.com/davglass/wiky.js/tarball/master", "timethat": "*", "git-travis": "~0.1.2", - "win-spawn": "*" + "win-spawn": "*", + "which": "*" }, "scripts": { "pretest": "jshint --config ./node_modules/yui-lint/jshint.json ./lib/*.js ./lib/*/*.js", diff --git a/tests/args.js b/tests/args.js index ee12ebc..a58c0e6 100644 --- a/tests/args.js +++ b/tests/args.js @@ -71,15 +71,6 @@ var tests = { assert.equal(topic.parsed.loglevel, 'silent'); } }, - 'should parse --json ': { - 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': { topic: function() { return args.parse(['', '', '--json']);