-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (47 loc) · 1.8 KB
/
index.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
#! /usr/bin/env node
import { program, Argument, Option } from "commander";
import * as cmds from "./commands/index.js";
import * as controllers from "./controller/index.js";
program
.name("transui")
.description("Help you transfer the tokens in SUI with just a few words")
.version("1.0.0");
Object.keys(controllers).map((key) => {
const keyCmd = `${key}Cmds`;
const cmdList = cmds[keyCmd];
const controller = controllers[key];
const mainCommand = program.command(key);
Object.keys(cmdList).forEach((command) => {
// Setup Sub-command
const subCommand = mainCommand
.command(cmdList[command].name)
.description(cmdList[command].description);
// Setup Args
const argList = cmdList[command]?.arguments || [];
argList.map((arg) => {
const argumentInstance = new Argument(arg.name, arg.description);
const choices = arg.choices || [];
const defaultValue = arg?.default?.value;
if (choices.length > 0) argumentInstance.choices(arg.choices);
// if (defaultValue)
// argumentInstance.default(defaultValue, arg.default.description);
subCommand.addArgument(argumentInstance);
});
// Setup Required Options
const requiredOtps = cmdList[command]?.requiredOptions || [];
requiredOtps.map((otp) => {
const optionInstance = new Option(otp.flags, otp.description);
const choices = otp.choices || [];
const defaultValue = otp?.default?.value;
if (choices.length > 0) optionInstance.choices(otp.choices);
// if (defaultValue)
// argumentInstance.default(defaultValue, arg.default.description);
subCommand.addOption(optionInstance);
});
// Build action
subCommand.action(async (...args) => {
await controller(args, cmdList[command].name);
});
});
});
program.parse();