forked from DarthMoulByte/unity-cache-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
executable file
·68 lines (64 loc) · 2.4 KB
/
main.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
#!/usr/bin/env node
require('./lib/helpers').initConfigDir(__dirname);
const cmd = require('commander');
const consts = require('./lib/constants');
const { version, description } = require('./package.json');
const { UnityCacheServer } = require('./lib/unity_cache_server');
function zeroOrMore(val) {
return Math.max(0, val);
}
function collect(val, memo) {
memo = memo || [];
memo.push(val);
return memo;
}
const optionMap = {
cacheModule: {
flags: "-c --cache-module <path>",
description: "The path to cache module. The Default path is 'cache_fs'.",
configKey: consts.CLI_CONFIG_KEYS.CACHE_MODULE
},
cachePath: {
flags: "-P, --cache-path <path>",
description: "The path of the cache directory.",
configKey: consts.CLI_CONFIG_KEYS.CACHE_PATH
},
host: {
flags: "-h, --host <address>",
description: "The interface on which the Cache Server listens. The default is to listen on all interfaces.",
configKey: consts.CLI_CONFIG_KEYS.HOST
},
port: {
flags: "-p, --port <n>",
description: "The port on which the Cache Server listens. The default value is 8126.",
validator: parseInt,
configKey: consts.CLI_CONFIG_KEYS.PORT
},
workers: {
flags: "-w, --workers <n>",
description: "The number of worker threads to spawn. The default is 0.",
validator: zeroOrMore,
configKey: consts.CLI_CONFIG_KEYS.WORKERS
},
mirror: {
flags: "-m --mirror <host:port>",
description: "Mirror transactions to another cache server. Repeat this option for multiple mirrors.",
validator: collect,
configKey: consts.CLI_CONFIG_KEYS.MIRROR
},
putwhitelist: {
flags: "-W --putwhitelist <host:port>",
description: "Only allow PUT transactions (uploads) from the specified client address. Repeat this option for multiple addresses.",
validator: collect,
configKey: consts.CLI_CONFIG_KEYS.PUTWHITELIST
},
diagClientRecorder: {
flags: "--diag-client-recorder",
description: "Record incoming client network stream to disk.",
configKey: consts.CLI_CONFIG_KEYS.CLIENT_RECORDER
}
};
// Initialize CLI handler
cmd.description(description).version(version).allowUnknownOption(true);
UnityCacheServer.handleCommandLine(cmd, optionMap);
UnityCacheServer.start().then(() => {}, () => process.exit(1));