-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·40 lines (34 loc) · 995 Bytes
/
cli.js
File metadata and controls
executable file
·40 lines (34 loc) · 995 Bytes
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
#!/usr/bin/env node
var commander = require('commander');
var proxy = require('./proxy.js');
commander
// .version(meta.version)
.usage('[options] <endpoint>')
.option('-p, --port <n>', 'Local proxy port, default 9200', parseInt)
.option('-b, --bindIf <ip>', 'Bind to interface, defaults to 127.0.0.1', /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/, '127.0.0.1')
.parse(process.argv);
if (commander.args.length != 1) {
console.error("Missing endpoint parameter");
commander.outputHelp();
process.exit(1);
}
var endpoint;
if (commander.args[0].startsWith('https://')) {
endpoint = commander.args[0];
} else {
endpoint = 'https://' + commander.args[0];
}
var region;
try {
region = endpoint.match(/\.([^.]+)\.es\.amazonaws\.com\.?$/)[1];
} catch (e) {
console.error('Region cannot be parsed from endpoint address');
process.exit(1);
}
var config = {
endpoint: endpoint,
region: region,
port: commander.port || 9200,
bindAddress: commander.bindIf
}
proxy.run(config);