-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
55 lines (50 loc) · 1.39 KB
/
cli.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
55
/**
* Copyright: E2E Technologies Ltd
*/
'use strict';
const conf = require('./conf.js'),
fs = require('fs-extra'),
exit = require('exit'),
argParser = new require('argparse').ArgumentParser({
'addHelp': true,
'epilog': 'Default is to display the configuration at stdout.'
});
argParser.addArgument(
'-u', {
'metavar': '<upload file>',
'help': 'Update configuration. Configuration is read from upload file.'
});
argParser.addArgument(
'configPath',
{
'help': 'Configuration path'
});
const args = argParser.parseArgs(),
uploadPath = args['u'];
conf.initOnlyFiles(args['configPath']);
if (uploadPath) {
fs.readJson(uploadPath, function (err, actualConfig) {
if (err) {
if (err instanceof SyntaxError) {
process.stderr.write(`Invalid JSON: ${err.message}`);
exit(1);
} else {
process.stderr.write(err.message);
exit(2);
}
}
if (actualConfig !== null) {
conf.save(actualConfig, function (err) {
if (err) {
process.stderr.write(err.message);
exit(2);
} else {
exit();
}
});
}
});
} else {
process.stdout.write(JSON.stringify(conf.get(), null, 2));
exit(0);
}