mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
feature(cloudcmd) add -c, --config
This commit is contained in:
parent
6b4da4978d
commit
50718c424f
3 changed files with 33 additions and 2 deletions
1
HELP.md
1
HELP.md
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue