mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(cloudcmd) start: add ability to override default config
This commit is contained in:
parent
8cbbc52a74
commit
1f4cabf15e
2 changed files with 41 additions and 31 deletions
|
|
@ -47,35 +47,7 @@
|
|||
function start(params) {
|
||||
var cloudcmd = require('../cloudcmd');
|
||||
|
||||
readConfig(function(msg, config) {
|
||||
if (params && params.test)
|
||||
config.test = params.test;
|
||||
|
||||
Util.log(msg);
|
||||
|
||||
cloudcmd.start(config);
|
||||
});
|
||||
}
|
||||
|
||||
function readConfig(callback) {
|
||||
var path = DIR + 'json/config.json';
|
||||
|
||||
Util.checkArgs(arguments, ['callback']);
|
||||
|
||||
fs.readFile(path, 'utf8', function(error, data) {
|
||||
var status, config, msg;
|
||||
|
||||
if (error) {
|
||||
status = 'error';
|
||||
} else {
|
||||
status = 'ok';
|
||||
config = Util.parseJSON(data);
|
||||
}
|
||||
|
||||
msg = CloudFunc.formatMsg('read', 'config', status);
|
||||
|
||||
callback(msg, config);
|
||||
});
|
||||
cloudcmd.start(params);
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
|
|||
42
cloudcmd.js
42
cloudcmd.js
|
|
@ -45,8 +45,26 @@
|
|||
/* reinit main dir os if we on Win32 should be backslashes */
|
||||
DIR = main.DIR;
|
||||
|
||||
exports.start = function(config) {
|
||||
init(config);
|
||||
exports.start = function(params) {
|
||||
readConfig(function(msg, config) {
|
||||
var keys;
|
||||
|
||||
Util.log(msg);
|
||||
|
||||
if (!config)
|
||||
config = {};
|
||||
|
||||
if (params) {
|
||||
keys = Object.keys(params);
|
||||
|
||||
keys.forEach(function(item) {
|
||||
config[item] = params[item];
|
||||
});
|
||||
}
|
||||
|
||||
init(config);
|
||||
|
||||
});
|
||||
|
||||
win.prepareCodePage();
|
||||
};
|
||||
|
|
@ -277,6 +295,26 @@
|
|||
});
|
||||
}
|
||||
|
||||
function readConfig(callback) {
|
||||
var path = DIR + 'json/config.json';
|
||||
|
||||
Util.checkArgs(arguments, ['callback']);
|
||||
|
||||
fs.readFile(path, 'utf8', function(error, data) {
|
||||
var status, config, msg;
|
||||
|
||||
if (error) {
|
||||
status = 'error';
|
||||
} else {
|
||||
status = 'ok';
|
||||
config = Util.parseJSON(data);
|
||||
}
|
||||
|
||||
msg = CloudFunc.formatMsg('read', 'config', status);
|
||||
|
||||
callback(msg, config);
|
||||
});
|
||||
}
|
||||
|
||||
/* function sets stdout to file log.txt */
|
||||
function writeLogsToFile() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue