diff --git a/bin/cloudcmd.js b/bin/cloudcmd.js index 04f48cd2..43538b9d 100755 --- a/bin/cloudcmd.js +++ b/bin/cloudcmd.js @@ -13,16 +13,20 @@ config = {}, argv = process.argv, + argvLength = argv.length, argvLast = argv.slice().pop(); switch (argvLast) { default: - if (isPort(argv)) { - if (argvLast - 0 > 0) - config.port = argvLast; - else - console.log('Error: port should be a number.'); - } + if (argvLength > 2) + if (isPort(argv)) { + if (argvLast - 0 > 0) + config.port = argvLast; + else + console.log('Error: port should be a number.'); + } + else + help(); start(config); @@ -44,6 +48,14 @@ case '--version': version(); break; + + case '-h': + help(); + break; + + case '--help': + help(); + break; } function version() { @@ -68,4 +80,24 @@ return is; } + function help() { + var bin = require('../json/bin'), + usage = 'Usage: cloudcmd [OPTION]...', + description = Info.description + '.', + + site = Util.render('General help using Cloud Commander: <{{ url }}>', { + url: Info.homepage + }); + + console.log(usage); + console.log(description + '\n'); + + Object.keys(bin).forEach(function(name) { + var line = ' ' + name + ' ' + bin[name]; + console.log(line); + }); + + console.log('\n' + site); + } + })(); diff --git a/json/bin.json b/json/bin.json new file mode 100644 index 00000000..a76fb9d8 --- /dev/null +++ b/json/bin.json @@ -0,0 +1,5 @@ +{ + "-h, --help ": "display this help and exit", + "-v, --version ":"output version information and exit", + "-p, --port ": "set port number and start" +} \ No newline at end of file