feature(cloudcmd) bin: add minimist

This commit is contained in:
coderaiser 2014-11-26 11:13:27 -05:00
parent 709ffd7631
commit 2773466f0f
2 changed files with 35 additions and 57 deletions

View file

@ -9,56 +9,46 @@
DIR_LIB = DIR + 'lib/',
Util = require(DIR_LIB + 'util'),
port,
argv = process.argv,
argvLength = argv.length,
argvLast = argv.slice().pop();
switch (argvLast) {
default:
port = argvLast - 0;
if (argvLength === 2)
start();
else
if (!isPort(argv))
help();
else
if (isNaN(port))
console.error('Error: port should be a number.');
else
start({
port: port
});
break;
argv = process.argv,
args = require('minimist')(argv.slice(2), {
string: 'port',
boolean: ['test', 'repl'],
alias: {
v: 'version',
h: 'help',
p: 'port' }
});
case '--test':
if (args.version) {
version();
} else if (args.help) {
help();
} else if (args.test) {
test();
} else if (!args.repl && !args.port) {
start();
} else {
if (args.repl)
repl();
if (!args.port)
start();
else
if (isNaN(args.port))
console.error('Error: port should be a number!');
else
start({
port: args.port
});
}
function test() {
Util.log('Cloud Commander testing mode');
Util.log('argv: ', argv);
require('..');
break;
case '-v':
version();
break;
case '--version':
version();
break;
case '-h':
help();
break;
case '--help':
help();
break;
case '--repl':
repl();
break;
}
function version() {
@ -71,18 +61,6 @@
require(SERVER)(config);
}
function isPort(argv) {
var length = argv.length,
str = argv
.slice(length - 2, length - 1)
.pop(),
PORT = ['-p', '--port'],
is = Util.strCmp(str, PORT);
return is;
}
function help() {
var bin = require('../json/bin'),
usage = 'Usage: cloudcmd [options]',
@ -105,7 +83,6 @@
function repl() {
console.log('REPL mode enabled (telnet localhost 1337)');
require(DIR_LIB + '/server/repl');
start();
}
})();

View file

@ -37,6 +37,7 @@
"marked": "~0.3.2",
"mellow": "~0.9.7",
"minify": "~1.3.0",
"minimist": "~1.1.0",
"pipe-io": "~1.1.1",
"ponse": "~1.2.8",
"socket.io": "~1.2.0",