feature(cloudcmd) add -c, --config

This commit is contained in:
coderaiser 2015-03-31 04:46:07 -04:00
parent 6b4da4978d
commit 50718c424f
3 changed files with 33 additions and 2 deletions

View file

@ -64,6 +64,7 @@ Cloud Commander supports command line parameters:
| `-a, --auth` | enable authorization
| `-u, --username` | set username
| `-p, --password` | set password
| `-c, --config` | configuration file path
| `--port` | set port number
| `--no-auth` | disable authorization
| `--no-server` | do not start server

View file

@ -23,6 +23,7 @@
'username',
'online',
'offline',
'config'
],
boolean: [
'auth',
@ -44,7 +45,8 @@
o: 'online',
u: 'username',
s: 'save',
a: 'auth'
a: 'auth',
c: 'config'
}
});
@ -63,6 +65,8 @@
config('online', args.online);
config('username', args.username);
readConfig(args.config);
if (args.save)
config.save(start);
else
@ -97,7 +101,27 @@
if (!isNaN(number))
config('port', number);
else
console.error('port: ignored, should be a number');
exit('port should be a number');
}
function readConfig(name) {
var fs, data, error, tryCatch;
if (name) {
fs = require('fs');
tryCatch = require('try-catch');
error = tryCatch(function() {
var json = fs.readFileSync(name);
data = JSON.parse(json);
});
if (error)
exit(error.message);
else
Object.keys(data).forEach(function(item) {
config(item, data[item]);
});
}
}
function help() {
@ -124,4 +148,9 @@
require(DIR_LIB + '/server/repl');
}
function exit(message) {
console.error(message);
process.exit(1);
}
})();

View file

@ -6,6 +6,7 @@
"-a, --auth " : "enable authorization",
"-u, --username " : "set username",
"-p, --password " : "set password",
"-c, --config " : "configuration file path",
"--port " : "set port number",
"--no-auth " : "disable authorization",
"--no-server " : "do not start server",