Permalink
Browse files

Adding support for yogi subcommands

  • Loading branch information...
1 parent 0196bb3 commit 9b21d184c6996ec363bed60c3c7114da9d6c95eb @davglass davglass committed Dec 5, 2012
Showing with 33 additions and 21 deletions.
  1. +31 −11 bin/yogi.js
  2. +2 −1 package.json
  3. +0 −9 tests/args.js
View
@@ -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(' '));
}
-
View
@@ -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",
View
@@ -71,15 +71,6 @@ var tests = {
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': {
topic: function() {
return args.parse(['', '', '--json']);

0 comments on commit 9b21d18

Please sign in to comment.