feature(config) show error.message when file exist, but could not be read from home

This commit is contained in:
coderaiser 2015-07-12 03:45:21 -04:00
parent 08ed4e6621
commit 6efbef5210

View file

@ -9,6 +9,7 @@
path = require('path'),
password = require(DIR_SERVER + 'password'),
exit = require(DIR_SERVER + 'exit'),
Util = require(DIR_LIB + 'util'),
CloudFunc = require(DIR_LIB + 'cloudfunc'),
@ -17,6 +18,7 @@
ponse = require('ponse'),
jonny = require('jonny'),
readjson = require('readjson'),
tryCatch = require('try-catch'),
HOME = require('os-homedir')(),
apiURL = CloudFunc.apiURL,
@ -24,9 +26,24 @@
ConfigPath = path.join(DIR, 'json/config.json'),
ConfigHome = path.join(HOME, '.cloudcmd.json'),
config =
readjson.sync.try(ConfigHome) ||
readjson.sync.try(ConfigPath);
error,
config;
error = tryCatch(function() {
config = readjson.sync(ConfigHome);
});
if (error) {
if (error.code !== 'ENOENT')
console.error('cloudcmd --config ~/.cloudcmd.json:', error.message);
error = tryCatch(function() {
config = readjson.sync(ConfigPath);
});
if (error)
exit('cloudcmd --config', ConfigPath + ':', error.message);
}
module.exports = manage;
module.exports.save = save;