Permalink
Browse files

Check for Jake/gen commands sooner, allow them to parse options

  • Loading branch information...
1 parent 4c0bef8 commit 517e18adb217377fe9a72c57a122e325366db874 mde committed Apr 22, 2013
Showing with 200 additions and 172 deletions.
  1. +105 −119 bin/cli.js
  2. +92 −49 lib/cmd.js
  3. +3 −4 usage.txt
View
@@ -1,136 +1,122 @@
#!/usr/bin/env node
-// Dependencies
var geddy = require('../lib/geddy')
, fs = require('fs')
, path = require('path')
, utils = require('utilities')
, parseopts = require('../lib/parseopts')
, cmd = require('../lib/cmd');
-// Variables
-var cwd = process.cwd()
- , args = process.argv.slice(2)
- , parser
- , optsMap
- , cmds
- , opts
- , usage
- , start;
+var args = process.argv.slice(2);
+args = cmd.parseArgs(args);
-// Options available
-optsMap = [
- { full: 'origins'
- , abbr: 'o'
- , args: true
- , canon: 'origins'
- }
-, { full: ['hostname', 'bind']
- , abbr: 'b'
- , args: true
- , canon: 'hostname'
- }
-, { full: 'port'
- , abbr: 'p'
- , args: true
- , canon: 'port'
- }
-, { full: 'workers'
- , abbr: ['n', 'w']
- , args: true
- , canon: 'workers'
- }
-, { full: 'version'
- , abbr: ['v', 'V']
- , args: false
- , canon: 'version'
- }
-, { full: 'help'
- , abbr: 'h'
- , args: false
- , canon: 'help'
- }
-, { full: 'debug'
- , abbr: 'd'
- , args: true
- , canon: 'debug'
- }
-, { full: 'loglevel'
- , abbr: 'l'
- , args: true
- , canon: 'loglevel'
- }
-, { full: 'environment'
- , abbr: 'e'
- , args: true
- , canon: 'environment'
- }
-, { full: 'geddy-root'
- , abbr: 'g'
- , args: true
- , canon: 'geddyRoot'
- }
-, { full: 'spawned'
- , abbr: ['s', 'q', 'Q']
- , args: true
- , canon: 'spawned'
- }
-, { full: 'jade'
- , abbr: 'j'
- , args: false
- , canon: 'jade'
- }
-, { full: ['handle', 'handlebars']
- , abbr: 'H'
- , args: false
- , canon: 'handlebars'
- }
-, { full: 'mustache'
- , abbr: 'm'
- , args: false
- , canon: 'mustache'
- }
-, { full: 'realtime'
- , abbr: 'rt'
- , args: false
- , canon: 'realtime'
- }
-];
+// Jake commands -- hand off to Jake to load up env
+// and run whatever command. Jake parses all the CLI
+// args itself
+if (args[0] == 'jake') {
+ args.shift();
+ var c = new cmd.JakeCmd(args);
+ c.run();
+}
+// Generator commands -- the Cmd object will parse
+// the args into commands and opts
+else if (args[0] == 'gen') {
+ args.shift();
+ var c = new cmd.Cmd(args);
+ c.run();
+}
+// Run the server
+else {
+ (function () {
+ var parser
+ , optsMap
+ , cmds
+ , opts
+ , usage
+ , die;
-// Parse optsMap and generate options and cmd commands
-parser = new parseopts.Parser(optsMap);
-parser.parse(args);
-cmds = parser.cmds;
-opts = parser.opts;
+ // Server options
+ optsMap = [
+ { full: 'origins'
+ , abbr: 'o'
+ , args: true
+ , canon: 'origins'
+ }
+ , { full: ['hostname', 'bind']
+ , abbr: 'b'
+ , args: true
+ , canon: 'hostname'
+ }
+ , { full: 'port'
+ , abbr: 'p'
+ , args: true
+ , canon: 'port'
+ }
+ , { full: 'workers'
+ , abbr: ['n', 'w']
+ , args: true
+ , canon: 'workers'
+ }
+ , { full: 'version'
+ , abbr: ['v', 'V']
+ , args: false
+ , canon: 'version'
+ }
+ , { full: 'help'
+ , abbr: 'h'
+ , args: false
+ , canon: 'help'
+ }
+ , { full: 'debug'
+ , abbr: 'd'
+ , args: true
+ , canon: 'debug'
+ }
+ , { full: 'loglevel'
+ , abbr: 'l'
+ , args: true
+ , canon: 'loglevel'
+ }
+ , { full: 'environment'
+ , abbr: 'e'
+ , args: true
+ , canon: 'environment'
+ }
+ , { full: 'geddy-root'
+ , abbr: 'g'
+ , args: true
+ , canon: 'geddyRoot'
+ }
+ , { full: 'spawned'
+ , abbr: ['s', 'q', 'Q']
+ , args: true
+ , canon: 'spawned'
+ }
+ ];
-// Set handlebars option to handle option
-opts.handle = opts.handlebars || opts.handle;
+ // Parse optsMap and generate options and cmd commands
+ parser = new parseopts.Parser(optsMap)
+ parser.parse(args);
+ cmds = parser.cmds;
+ opts = parser.opts;
-// Exit the process with a message
-die = function (str) {
- console.log(str);
- process.exit();
-};
+ // Exit the process with a message
+ die = function (str) {
+ console.log(str);
+ process.exit();
+ };
-// Start Geddy with options
-start = function () {
- geddy.startCluster(opts);
-};
+ if (opts.help) {
+ var usage = fs.readFileSync(path.join(__dirname, '..',
+ 'usage.txt')).toString();
+ return die(usage);
+ }
-if (opts.help) {
- var usage = fs.readFileSync(path.join(__dirname, '..',
- 'usage.txt')).toString();
- die(usage);
-}
-if (opts.version) {
- die(geddy.version);
-}
+ if (opts.version) {
+ return die(geddy.version);
+ }
-// `geddy app foo` or `geddy resource bar` etc. -- run generators
-if (cmds.length) {
- cmd.run(cmds, opts);
-}
-// Just `geddy` -- start the server
-else {
- start();
+ geddy.startCluster(opts);
+ })();
}
+
Oops, something went wrong.

0 comments on commit 517e18a

Please sign in to comment.