Permalink
Browse files

[refactor] Use flatiron in bin/haibu

  • Loading branch information...
1 parent 41e75a5 commit 2c0a8c166a6bf60648e041e97bdd155d20c42323 @Southern Southern committed Oct 20, 2012
Showing with 111 additions and 55 deletions.
  1. +94 −42 bin/haibu
  2. +17 −13 lib/haibu/common/index.js
View
136 bin/haibu
@@ -2,50 +2,102 @@
var path = require('path'),
util = require('util'),
- argv = require('optimist').argv,
- haibu = require('../lib/haibu');
-
-var help = [
- 'usage: haibu-server [options]',
- '',
- 'Starts the haibu API server responsible for spawning node.js applications.',
- '',
- 'options:',
- ' -a IP Address that you want the server to bind to [dynamic]',
- ' -p Port that you want the server to run on [9002]',
- ' -e [env] The environment to the specified command in [development]',
- ' --logger Use the haibu logger plugin [true]',
- ' --advanced-replies Send extra info with replies',
- ' -s --silent Suppress the log messages from the output',
- ' -h, --help You\'re staring at it',
-].join('\n');
-
-if (argv.h || argv.help) {
- return util.puts(help);
-}
+ haibu = require('../lib/haibu'),
+ flatiron = require('flatiron'),
+ app = flatiron.app;
-var address = argv.a || haibu.common.ipAddress(),
- port = argv.p || 9002,
- env = argv.env || 'development';
+app.use(flatiron.plugins.cli, {
+ usage: haibu.common.welcome.concat([
+ 'Commands:',
+ ' start Start the server.',
+ ' help You\'re looking at it!'
+ ]),
-if (argv.useraccounts) {
- haibu.use(haibu.useraccounts, {});
-}
+ argv: {
+ address: {
+ alias: 'a',
+ description: 'IP address for the server to bind to.',
+ string: true,
+ default: 'dynamic'
+ },
+ port: {
+ alias: 'p',
+ description: 'Port for the server to listen on.',
+ check: function(argv) {
+ if (isNaN(parseInt(argv.port))) return false;
+ },
+ default: 9002
+ },
+ env: {
+ alias: 'e',
+ description: 'Environment to run the server in.',
+ string: true,
+ default: 'development'
+ },
+ logger: {
+ description: 'Use the Haibu Logger plugin.',
+ boolean: true
+ },
+ 'advanced-replies': {
+ description: 'Send extra info with replies.',
+ boolean: true
+ },
+ silent: {
+ alias: 's',
+ description: 'Suppress the log messages from the output.',
+ boolean: true
+ },
+ useraccounts: {
+ alias: 'u',
+ description: 'Use the Haibu User Accounts plugin.',
+ boolean: true
+ },
+ coffee: {
+ alias: 'c',
+ description: 'Use the Haibu CoffeeScript plugin.',
+ boolean: true
+ },
+ help: {
+ alias: 'h',
+ description: 'You\'re looking at it!',
+ boolean: true
+ }
+ }
+});
-if (argv.coffee) {
- haibu.use(haibu.coffee, {});
-}
+var start = app.commands.start = function(address, port, env) {
+ address = address || app.argv.address || haibu.common.ipAddress();
+ port = port || parseInt(app.argv.port) || 9002;
+ env = env || app.argv.env || 'development';
-if (argv['advanced-replies']) {
- haibu.use(haibu['advanced-replies'], {});
-}
+ if (app.argv.useraccounts) {
+ haibu.use(haibu.useraccounts, {});
+ }
-haibu.config.file({ file: path.join(__dirname, '..', 'config', 'config.json') });
-
-haibu.drone.start({
- env: env,
- port: port,
- host: address
-}, function () {
- haibu.utils.showWelcome('api-server', address, port);
-});
+ if (app.argv.coffee) {
+ haibu.use(haibu.coffee, {});
+ }
+
+ if (app.argv['advanced-replies']) {
+ haibu.use(haibu['advanced-replies'], {});
+ }
+
+ haibu.config.file({ file: path.join(__dirname, '..', 'config', 'config.json') });
+
+ haibu.drone.start({
+ env: env,
+ port: port,
+ host: address
+ }, function () {
+ haibu.utils.showWelcome('api-server', address, port);
+ });
+};
+
+
+// If no command was given, immediately start haibu.
+if (app.argv._.length == 0 && !app.argv.help) {
+ start();
+}
+else {
+ app.start();
+}
View
@@ -40,6 +40,21 @@ if (!Error.prototype.toJSON) {
//
var npm = common.npm = require('./npm');
+common.welcome = [
+ ' __ __ '.yellow,
+ ' / /_ ______ __ / /_ __ __ '.yellow,
+ ' / __ \\ / __ / / / / __ \\ / / / / '.yellow,
+ ' / / / / / /_/ / / / / /_/ / / /_/ / '.yellow,
+ ' /_/ /_/ \\__,_/ /_/ /_/\\___/ \\__,_/ '.yellow,
+ ' ',
+ ' This is Open Source Software available under'.grey,
+ ' the MIT License.'.grey,
+ ' ',
+ ' © 2010 Nodejitsu Inc.'.grey,
+ ' All Rights Reserved - www.nodejitsu.com'.grey,
+ ''
+];
+
//
// ### function showWelcome (mode, ipAddress, port)
// #### @mode {string} The mode that haibu is currently running in.
@@ -61,19 +76,8 @@ common.showWelcome = function (role, ipAddress, port) {
role.green.bold
].join(' ');
- console.log(' __ __ '.yellow);
- console.log(' / /_ ______ __ / /_ __ __ '.yellow);
- console.log(' / __ \\ / __ / / / / __ \\ / / / / '.yellow);
- console.log(' / / / / / /_/ / / / / /_/ / / /_/ / '.yellow);
- console.log(' /_/ /_/ \\__,_/ /_/ /_/\\___/ \\__,_/ '.yellow);
- console.log(' ');
- console.log(' This is Open Source Software available under'.grey);
- console.log(' the MIT License.'.grey);
- console.log(' ');
- console.log(' © 2010 Nodejitsu Inc.'.grey);
- console.log(' All Rights Reserved - www.nodejitsu.com'.grey);
-
- console.log(' ' + serverMsg);
+ console.log(common.welcome.join('\n'));
+ console.log(' ' + serverMsg);
//
// If there are any active plugins then

0 comments on commit 2c0a8c1

Please sign in to comment.