-
Notifications
You must be signed in to change notification settings - Fork 38
/
console.ts
52 lines (42 loc) · 1.49 KB
/
console.ts
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
import { Command, flags } from "@oclif/command";
import { getEnv } from "../lib/env";
import * as path from "path";
import * as repl from "repl";
import * as terrajs from "@terra-money/terra.js";
export default class Console extends Command {
static description =
"Start a repl console that provides context and convinient utilities to interact with the blockchain and your contracts.";
static flags = {
network: flags.string({ default: "localterra" }),
"config-path": flags.string({ default: "config.terrain.json" }),
"refs-path": flags.string({ default: "refs.terrain.json" }),
"keys-path": flags.string({ default: "keys.terrain.js" }),
};
static args = [];
async run() {
const { args, flags } = this.parse(Console);
const fromCwd = (p: string) => path.join(process.cwd(), p);
const env = getEnv(
fromCwd(flags["config-path"]),
fromCwd(flags["keys-path"]),
fromCwd(flags["refs-path"]),
flags.network
);
const lib = require(path.join(process.cwd(), "lib"));
// for repl server
const { config, refs, wallets, client } = env;
const r = repl.start({ prompt: "terrain > ", useColors: true });
const def = (name: string, value: any) =>
Object.defineProperty(r.context, name, {
configurable: false,
enumerable: true,
value,
});
def("config", config);
def("refs", refs);
def("wallets", wallets);
def("client", client);
def("terrajs", terrajs);
def("lib", lib(env));
}
}