-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
47 lines (40 loc) · 1.64 KB
/
cli.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
const init = require("./lib/initManager");
/* eslint-disable global-require */
const commands = {
generateSigningKeyPair: require("./commands/generateSigningKeyPair"),
generateAddresses: require("./commands/generateAddresses"),
monitorChain: require("./commands/monitorChain"),
validateAddresses: require("./commands/validateAddresses"),
validateDeposits: require("./commands/validateDeposits"),
watchDeposits: require("./commands/watchDeposits"),
help: require("./commands/help"),
};
/* eslint-enable global-require */
(async () => {
let initResult = {};
// If request is a help request display help and exit.
try {
if (process.argv[2] === "help") {
await commands.help(process.argv[3]);
return;
}
// Run generateSigningKeyPair escript and exit.
if (process.argv[2] === "generateSigningKeyPair") {
await commands.generateSigningKeyPair();
return;
}
// Pass commands and option to initManager for validation and parsing.
initResult = await init(process.argv);
} catch (e) {
console.log(e.message);
return;
}
// Destructure initResult object to local constants.
const { command, options, config, requestManager, logManager } = initResult;
// Run command with provided options and required libraries. If a result message is returned it is returned by throwing a LogMessage exception. This exception is caught here and processed by the logManager which determines if the results are sent to console and/or Telegram.
try {
await commands[command](options, config, requestManager, logManager);
} catch (e) {
logManager.log(e.message, e.logToConsole, e.sendToTg);
}
})();