-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
77 lines (70 loc) · 1.52 KB
/
index.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env node
import readline from 'readline';
import { Config } from 'cli-conf';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { Rcon } from './rcon.js';
const argv = yargs(hideBin(process.argv))
.locale('en')
.scriptName('rcon')
.strictOptions()
.option('host', {
alias: ['h'],
type: 'string',
})
.option('port', {
alias: ['p'],
type: 'number',
})
.option('password', {
alias: ['P'],
type: 'string',
})
.option('timeout', {
alias: ['t'],
type: 'number',
})
.positional('id', {
type: 'string',
desc: 'host address or identifier declared in ~/.config/rcon.json',
})
.argv;
const configData = new Config('rcon');
const config = {
host: '',
port: 25575,
password: '',
timeout: 5000,
};
if (configData.default) {
Object.assign(config, configData.default);
}
if (argv._.length > 0) {
Object.assign(config, configData[argv._[0]]);
}
if (argv.host) {
config.host = argv.host;
}
if (argv.port) {
config.port = argv.port;
}
if (argv.password) {
config.password = argv.password;
}
if (argv.timeout) {
config.timeout = argv.timeout;
}
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const rcon = new Rcon(config);
rl.on('line', async line => {
if (/^exit$/.test(line)) {
rl.close();
process.exit(0);
}
console.log(await rcon.send(line));
rl.prompt();
});
rl.prompt();