-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparameters.js
54 lines (42 loc) · 1.22 KB
/
parameters.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var parser = require('argv-parser');
var fs = require('fs');
var path = require('path');
function parse(argv) {
var result = parser.parse(argv, {
rules: {
logLevel: {
type: String,
value: 'ERROR'
},
logToFile: {
type: Boolean,
value: false
},
configFile: {
type: String,
value: 'config.json'
},
convertToOpenHab: {
type: Boolean,
value: true
}
}
});
if (result.parsed.logToFile) {
result.parsed.logToScreen = false;
}
result.parsed.mqtt = {topic: 'topic'};
return result.parsed;
}
function mergeWithFileConfig(argData) {
const exist = fs.existsSync(path.resolve(argData.configFile));
const data = fs.readFileSync(path.resolve(argData.configFile));
if (data) {
argData = Object.assign(argData, JSON.parse(data.toString()));
}
return argData;
}
mergeWithFileConfig(parse(process.argv));
module.exports = {
parameters: mergeWithFileConfig(parse(process.argv))
};