-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
49 lines (44 loc) · 970 Bytes
/
app.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
#!/usr/bin/env node
const nopt = require("nopt");
const linebyline = require("linebyline");
const buffer = require("buffer");
let options = {
address: "127.0.0.1",
port: "514",
path: "/",
echo: true,
reconnect: true,
reconnectTries: Infinity,
};
const longOpts = {
address: String,
port: Number,
path: String,
reconnect: Boolean,
reconnectTries: Number,
echo: Boolean,
debug: Boolean,
};
const shortOpts = {
a: "--address",
p: "--port",
pa: "--path",
r: "--reconnect",
t: "--reconnectTries",
e: "--echo",
d: "--debug",
};
const argv = nopt(longOpts, shortOpts, process.argv);
options = Object.assign(options, argv);
if (options.debug) {
console.log("Starting up!");
}
const webSocketStream = require("./lib/websocket")(options);
linebyline(process.stdin, {
maxLineLength: buffer.constants.MAX_LENGTH,
}).on("line", (chunk) => {
webSocketStream.write(chunk);
});
process.stdin.on("close", () => {
process.exit(0);
});