-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfd
executable file
·73 lines (58 loc) · 2.31 KB
/
confd
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env node
'use strict';
let rest = require('./rest');
let confd = require('./index');
let docopt = require('docopt').docopt;
let DEFAULT_PORT = 6868;
let DEFAULT_FROM = '/etc/conf.d';
function startRest(port, from, strategy)
{
port = port || DEFAULT_PORT;
from = from || DEFAULT_FROM;
console.log('Going to start conf.d service on port "%s", from folder "%s"...', port, from);
rest.run(from, port, strategy);
}
function startCli(path, subpath, strategy)
{
strategy = strategy || confd.strategy().default();
let conf = confd.from(path).strategy().set(strategy);
conf.get(subpath)
.then( json =>
{
console.log(JSON.stringify(json, null, 4));
})
.catch( err =>
{
console.error('Could not load configuration from "%s" (subpath is "%s"). %s', path, subpath, err);
process.exit(1);
});
}
let options = 'Either starts the conf.d REST server or the command-line reader \n'
+ ' \n'
+ 'Usage: \n'
+ ' confd cli get <PATH> [<SUBPATH>] [--strategy leaves|backcursion|array]\n'
+ ' confd rest [--port <PORT>] [--from <FOLDER>] [--strategy leaves|backcursion|array]\n'
+ ' confd -h | --help \n'
+ ' \n'
+ 'Modes: \n'
+ ' cli Starts the command-line reader\n'
+ ' rest Starts the REST server\n'
+ ' \n'
+ 'Options: \n'
+ ' get <PATH> [<SUBPATH>] Read the JSON object from <PATH>, eventually scoped to sub-path <SUBPATH> \n'
+ ' --strategy leaves|backcursion|array Choose the strategy to be used to unify the documents (default is "' + confd.strategy().default().toLowerCase() + '") \n'
+ ' --port <PORT> Instructs the REST server to listen on port <PORT>. Default port is ' + DEFAULT_PORT + '. \n'
+ ' --from <FOLDER> Instructs the REST server to read data from <FOLDER>. Default folder is ' + DEFAULT_FROM + '. \n'
+ ' -h --help Shows this help \n';
let cmd = docopt(options);
if (cmd)
{
if (cmd.rest)
{
startRest(cmd['--port'], cmd['--from'], cmd['--strategy']);
}
else if (cmd.cli)
{
startCli(cmd['<PATH>'], cmd['<SUBPATH>'], cmd['--strategy']);
}
}