-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.ts
More file actions
64 lines (58 loc) · 1.83 KB
/
index.ts
File metadata and controls
64 lines (58 loc) · 1.83 KB
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
import {read_ir, opc, opd, run, brun} from "./clvm_tools/cmds";
export * from "./clvm_tools/binutils";
export * from "./clvm_tools/clvmc";
export * from "./clvm_tools/cmds";
export * from "./clvm_tools/curry";
export * from "./clvm_tools/debug";
export * from "./clvm_tools/NodePath";
export * from "./clvm_tools/pattern_match";
export * from "./clvm_tools/sha256tree";
import {setStdout, TPrinter} from "./platform/print";
import {initialize as initClvm} from "clvm";
import {initialize as initClvmRs, TInitOption as TInitClvmRsOption} from "./platform/clvm_rs";
const COMMANDS: Record<string, (args: string[]) => unknown> = {
read_ir,
opc,
opd,
run,
brun,
};
/**
* Dispatch cli command.
* - `go("run", "(mod ARGUMENT (+ ARGUMENT 3))")`
* - `go("brun", "(+ 1 (q . 3))", "--time")`
*
* @param {...string[]} args
*/
export function go(...args: string[]){
if(!args || args.length < 1){
const errMsg = "You need specify command";
// printError(`Error: ${errMsg}`);
throw new Error(errMsg);
}
const commandName = args[0];
const command = COMMANDS[commandName];
if(!command){
const errMsg = `Unknown command: ${commandName}`;
// printError(`Error: ${errMsg}`);
throw new Error(errMsg);
}
return command(args);
}
/**
* Change print function. Default is `console.log`.
* If you want to print messages to file, variable or something, you need to change printer function by this function.
* @param {(...msg: string[]) => void} printer
*/
export function setPrintFunction(printer: TPrinter){
setStdout(printer);
}
export type TInitOption = {
initClvmRsOption: TInitClvmRsOption;
};
/**
* Wait wasm files to be loaded before you call any of `clvm_tools` functions.
*/
export async function initialize(option?: Partial<TInitOption>){
await Promise.all([initClvm(), initClvmRs(option?.initClvmRsOption)]);
}