-
Notifications
You must be signed in to change notification settings - Fork 32
/
cli.js
executable file
·84 lines (77 loc) · 2.17 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
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
78
79
80
81
82
83
84
#!/usr/bin/env node
const os = require("os");
const fs = require("fs");
const { sep } = require("path");
const { program, CommanderError } = require("commander");
const run = require("./main");
const packageJson = require("./package.json");
function getOptions(program) {
return {
workdir: program.workdir || fs.mkdtempSync(`${os.tmpdir()}${sep}`),
port: program.port,
period: program.period,
download: program.download,
logging: program.logging,
allocate: program.allocate,
chainId: program.chainid,
execute: program.execute,
nodeArguments: program.nodeArguments,
};
}
function parseChainId(value) {
if (value === "random") {
return 1e9 + Math.round(Math.random() * 1e9);
} else {
return parseInt(value, 10);
}
}
program
.version(packageJson.version)
.option("-d, --download", "Download the Ethereum client and exit.")
.option("-w, --workdir <dir>", "Specify a working dir.")
.option(
"--period <number>",
"Block period in secods, 0 = mine only if transaction pending",
(v) => parseInt(v, 10),
0
)
.option(
"-p, --port <port>",
"Specify the JSONRPC port.",
(v) => parseInt(v, 10),
8545
)
.option("-l, --logging <level>", "Specify logging level (error, warn, info).")
.option(
"-c, --chainid <int>",
'Set the chainId (also called network id), can be an int or the string "random".',
parseChainId,
666666
)
.option(
"-a, --allocate <addresses>",
"Comma separated list of addresses. Allocate 100 Ethers for each address.",
(val) => val.split(","),
[]
)
.option(
"-e, --execute <command>",
"Start ethnode, execute command, and exit ethnode (useful for testing)."
)
.option(
"--node-arguments <args>",
"Arguments that are passed directly to ethnode's underlying Ethereum node."
);
program
.command("openethereum")
.description("Run an Openethereum development node.")
.action((cmd) => {
run("openethereum", getOptions(program.opts()));
});
program
.command("geth", { isDefault: true })
.description("Run a Geth development node.")
.action((cmd) => {
run("geth", getOptions(program.opts()));
});
program.parse(process.argv);