mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-28 18:23:35 +00:00
feature(config) add ability to override absent values in config
This commit is contained in:
parent
a127ac9b53
commit
1c934d5a82
2 changed files with 18 additions and 20 deletions
|
|
@ -24,28 +24,25 @@ const apiURL = CloudFunc.apiURL;
|
|||
const ConfigPath = path.join(DIR, 'json/config.json');
|
||||
const ConfigHome = path.join(HOME, '.cloudcmd.json');
|
||||
|
||||
const readjsonSync = (name) => jju.parse(fs.readFileSync(name, 'utf8'), {
|
||||
mode: 'json'
|
||||
});
|
||||
const readjsonSync = (name) => {
|
||||
return jju.parse(fs.readFileSync(name, 'utf8'), {
|
||||
mode: 'json'
|
||||
});
|
||||
};
|
||||
|
||||
const rootConfig = readjsonSync(ConfigPath);
|
||||
|
||||
const key = (a) => Object.keys(a).pop();
|
||||
|
||||
let config;
|
||||
let configHome;
|
||||
let error = tryCatch(() => {
|
||||
config = readjsonSync(ConfigHome);
|
||||
configHome = readjsonSync(ConfigHome);
|
||||
});
|
||||
|
||||
if (error) {
|
||||
if (error.code !== 'ENOENT')
|
||||
console.error('cloudcmd --config ~/.cloudcmd.json:', error.message);
|
||||
|
||||
error = tryCatch(() => {
|
||||
config = readjsonSync(ConfigPath);
|
||||
});
|
||||
|
||||
if (error)
|
||||
exit('cloudcmd --config', ConfigPath + ':', error.message);
|
||||
}
|
||||
if (error && error.code !== 'ENOENT')
|
||||
exit(`cloudcmd --config ${ConfigHome}: ${error.message}`);
|
||||
|
||||
const config = Object.assign({}, rootConfig, configHome);
|
||||
|
||||
module.exports = manage;
|
||||
module.exports.save = save;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue