diff --git a/HELP.md b/HELP.md index 782e8355..e962d77a 100644 --- a/HELP.md +++ b/HELP.md @@ -60,7 +60,10 @@ Cloud Commander supports command line parameters: |:----------------------|:-------------------------------------------- | `-h, --help` | display help and exit | `-v, --version` | output version information and exit -| `-p, --port` | set port number and start +| `-s, --save` | save options +| `-p, --port` | set port number +| `-u, --username` | set username +| `-ps, --password` | set password If no parameters given Cloud Commander reads information from `~/.cloudcmd.json` and use port from it (`8000` default). if port variables `PORT` or `VCAP_APP_PORT` isn't exist. diff --git a/bin/cloudcmd.js b/bin/cloudcmd.js index d7d84a9b..931c89a1 100755 --- a/bin/cloudcmd.js +++ b/bin/cloudcmd.js @@ -3,23 +3,29 @@ (function() { 'use strict'; - var Info = require('../package'), + var config, + Info = require('../package'), DIR = __dirname + '/../', DIR_LIB = DIR + 'lib/', + DIR_SERVER = DIR_LIB + 'server/', rendy = require('rendy'), + createPass = require(DIR_SERVER + 'password'), HOME_PAGE = 'General help using Cloud Commander: <{{ url }}>', argv = process.argv, args = require('minimist')(argv.slice(2), { - string: 'port', - boolean: ['test', 'repl'], + string: ['port', 'password', 'username'], + boolean: ['test', 'repl', 'save'], alias: { v: 'version', h: 'help', - p: 'port' + p: 'port', + u: 'username', + ps: 'password', + s: 'save' } }); @@ -29,22 +35,20 @@ help(); } else if (args.test) { test(); - } else if (!args.repl && !args.port) { - start(); } else { if (args.repl) repl(); - if (!args.port) - start(); + config = require(DIR_SERVER + 'config'); + + password(args.password); + username(args.username); + port(args.port); + + if (args.save) + config.save(start); else - if (isNaN(args.port)) - console.error('Error: port should be a number!'); - else - start({ - port: args.port - }); - + start(); } function test() { @@ -64,6 +68,31 @@ require(SERVER)(config); } + function password(pass) { + var algo, hash; + + if (pass) { + algo = config('algo'); + hash = createPass(algo, pass); + + config('password', hash); + } + } + + function username(name) { + if (name) + config('username', name); + } + + function port(number) { + if (port) { + if (!isNaN(number)) + config('port', number); + else + console.error('port: ignored, should be a number'); + } + } + function help() { var bin = require('../json/bin'), usage = 'Usage: cloudcmd [options]', diff --git a/json/bin.json b/json/bin.json index 5277fa83..39b38a62 100644 --- a/json/bin.json +++ b/json/bin.json @@ -1,5 +1,8 @@ { - "-h, --help ": "display this help and exit", - "-v, --version ": "output version information and exit", - "-p, --port ": "set port number and start" + "-h, --help " : "display this help and exit", + "-v, --version " : "output version information and exit", + "-s, --save " : "save options", + "-p, --port " : "set port number", + "-u, --username " : "set username", + "-ps, --password" : "set password" }