clients/js: refactor cmds & CLI docs generator (#3182)
* feat: update npm commands for Githun Actions CI * feat: add worm cli github actions * feat: save HTML test report as artifact * chore: update github action, show report correctly * fix: add missing CommandModule type * chore: rm unused import * fix: override auto-detected locale by OS system * feat: infere command modules on doc.ts & main.ts * feat: command args accepts an array of modules * fix: cmds must be outside main, breaks otherwise * fix: import CLI_COMMAND_MODULES outside of main * chore: add missing transfer command from README * chore: rm test branch dependencies * feat: extract info cmds into array const * chore: document command imports as list * chore: package.json spacing * chore: bump @types/yargs version * feat: cast correct array type YargsCommandModule[]
This commit is contained in:
parent
03bf786b47
commit
8e0cf4c31f
|
@ -298,6 +298,33 @@ Options:
|
|||
```
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary> transfer </summary>
|
||||
|
||||
```sh
|
||||
Options:
|
||||
--help Show help [boolean]
|
||||
--version Show version number [boolean]
|
||||
--src-chain source chain
|
||||
[required] [choices: "solana", "ethereum", "terra", "bsc", "polygon",
|
||||
"avalanche", "oasis", "algorand", "aurora", "fantom", "karura", "acala",
|
||||
"klaytn", "celo", "near", "moonbeam", "neon", "terra2", "injective",
|
||||
"osmosis", "sui", "aptos", "arbitrum", "optimism", "gnosis", "pythnet",
|
||||
"xpla", "btc", "base", "sei", "wormchain", "sepolia"]
|
||||
--dst-chain destination chain
|
||||
[required] [choices: "solana", "ethereum", "terra", "bsc", "polygon",
|
||||
"avalanche", "oasis", "algorand", "aurora", "fantom", "karura", "acala",
|
||||
"klaytn", "celo", "near", "moonbeam", "neon", "terra2", "injective",
|
||||
"osmosis", "sui", "aptos", "arbitrum", "optimism", "gnosis", "pythnet",
|
||||
"xpla", "btc", "base", "sei", "wormchain", "sepolia"]
|
||||
--dst-addr destination address [string] [required]
|
||||
--token-addr token address [string] [default: native token]
|
||||
--amount token amount [string] [required]
|
||||
-n, --network Network [required] [choices: "mainnet", "testnet", "devnet"]
|
||||
--rpc RPC endpoint [string]
|
||||
```
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary> verify-vaa </summary>
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
"@types/bn.js": "^5.1.0",
|
||||
"@types/bs58": "^4.0.1",
|
||||
"@types/node-fetch": "^2.6.3",
|
||||
"@types/yargs": "^17.0.2",
|
||||
"@types/yargs": "^17.0.24",
|
||||
"copy-dir": "^1.3.0",
|
||||
"typescript": "^4.6"
|
||||
}
|
||||
|
@ -3531,9 +3531,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@types/yargs": {
|
||||
"version": "17.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.2.tgz",
|
||||
"integrity": "sha512-JhZ+pNdKMfB0rXauaDlrIvm+U7V4m03PPOSVoPS66z8gf+G4Z/UW8UlrVIj2MRQOBzuoEvYtjS0bqYwnpZaS9Q==",
|
||||
"version": "17.0.24",
|
||||
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz",
|
||||
"integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/yargs-parser": "*"
|
||||
|
@ -10878,9 +10878,9 @@
|
|||
}
|
||||
},
|
||||
"@types/yargs": {
|
||||
"version": "17.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.2.tgz",
|
||||
"integrity": "sha512-JhZ+pNdKMfB0rXauaDlrIvm+U7V4m03PPOSVoPS66z8gf+G4Z/UW8UlrVIj2MRQOBzuoEvYtjS0bqYwnpZaS9Q==",
|
||||
"version": "17.0.24",
|
||||
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz",
|
||||
"integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/yargs-parser": "*"
|
||||
|
|
|
@ -65,7 +65,7 @@
|
|||
"@types/bn.js": "^5.1.0",
|
||||
"@types/bs58": "^4.0.1",
|
||||
"@types/node-fetch": "^2.6.3",
|
||||
"@types/yargs": "^17.0.2",
|
||||
"@types/yargs": "^17.0.24",
|
||||
"copy-dir": "^1.3.0",
|
||||
"typescript": "^4.6"
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import yargs from "yargs";
|
||||
import yargs, { CommandModule } from "yargs";
|
||||
|
||||
export class Yargs {
|
||||
yargs: typeof yargs;
|
||||
|
@ -16,3 +16,5 @@ export class Yargs {
|
|||
}
|
||||
|
||||
export type YargsAddCommandsFn = (y: typeof yargs) => typeof yargs;
|
||||
|
||||
export type YargsCommandModule = CommandModule<any, any>;
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
// https://github.com/yargs/yargs/blob/main/docs/advanced.md#example-command-hierarchy-using-indexmjs
|
||||
import * as aptos from "./aptos";
|
||||
import * as editVaa from "./editVaa";
|
||||
import * as evm from "./evm";
|
||||
import * as generate from "./generate";
|
||||
import * as info from "./info";
|
||||
import * as near from "./near";
|
||||
import * as parse from "./parse";
|
||||
import * as recover from "./recover";
|
||||
import * as submit from "./submit";
|
||||
import * as sui from "./sui";
|
||||
import * as transfer from "./transfer";
|
||||
import * as verifyVaa from "./verifyVaa";
|
||||
import * as status from "./status";
|
||||
|
||||
// Commands can be imported as an array of commands.
|
||||
// Documentation about command hierarchy can be found here: https://github.com/yargs/yargs/blob/main/docs/advanced.md#example-command-hierarchy-using-indexmjs
|
||||
export const CLI_COMMAND_MODULES = [
|
||||
aptos,
|
||||
editVaa,
|
||||
evm,
|
||||
generate,
|
||||
info,
|
||||
near,
|
||||
parse,
|
||||
recover,
|
||||
submit,
|
||||
sui,
|
||||
transfer,
|
||||
verifyVaa,
|
||||
status,
|
||||
];
|
|
@ -1,22 +1,12 @@
|
|||
import yargs from "yargs";
|
||||
import * as chainId from "./chainId";
|
||||
import * as contract from "./contract";
|
||||
import * as emitter from "./emitter";
|
||||
import * as origin from "./origin";
|
||||
import * as registrations from "./registrations";
|
||||
import * as rpc from "./rpc";
|
||||
import * as wrapped from "./wrapped";
|
||||
import { YargsCommandModule } from "../Yargs";
|
||||
import { INFO_COMMANDS } from "./info";
|
||||
|
||||
export const command = "info";
|
||||
export const desc = "Contract, chain, rpc and address information utilities";
|
||||
// Imports modules logic from root commands, more info here -> https://github.com/yargs/yargs/blob/main/docs/advanced.md#providing-a-command-module
|
||||
export const builder = (y: typeof yargs) =>
|
||||
y
|
||||
.command(chainId)
|
||||
.command(contract)
|
||||
.command(emitter)
|
||||
.command(origin)
|
||||
.command(registrations)
|
||||
.command(rpc)
|
||||
.command(wrapped);
|
||||
// Commands can be imported as an array of commands.
|
||||
// Documentation about command hierarchy can be found here: https://github.com/yargs/yargs/blob/main/docs/advanced.md#example-command-hierarchy-using-indexmjs
|
||||
y.command(INFO_COMMANDS as unknown as YargsCommandModule[]);
|
||||
export const handler = () => {};
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
import * as chainId from "./chainId";
|
||||
import * as contract from "./contract";
|
||||
import * as emitter from "./emitter";
|
||||
import * as origin from "./origin";
|
||||
import * as registrations from "./registrations";
|
||||
import * as rpc from "./rpc";
|
||||
import * as wrapped from "./wrapped";
|
||||
|
||||
// Commands can be imported as an array of commands.
|
||||
// Documentation about command hierarchy can be found here: https://github.com/yargs/yargs/blob/main/docs/advanced.md#example-command-hierarchy-using-indexmjs
|
||||
export const INFO_COMMANDS = [
|
||||
chainId,
|
||||
contract,
|
||||
emitter,
|
||||
origin,
|
||||
registrations,
|
||||
rpc,
|
||||
wrapped,
|
||||
];
|
|
@ -1,22 +1,9 @@
|
|||
import * as fs from "fs";
|
||||
|
||||
import yargs from "yargs";
|
||||
// Side effects are here to trigger before the afflicted libraries' on-import warnings can be emitted.
|
||||
// It is also imported so that it can side-effect without being tree-shaken.
|
||||
import "./side-effects";
|
||||
// https://github.com/yargs/yargs/blob/main/docs/advanced.md#example-command-hierarchy-using-indexmjs
|
||||
import * as aptos from "./cmds/aptos";
|
||||
import * as editVaa from "./cmds/editVaa";
|
||||
import * as evm from "./cmds/evm";
|
||||
import * as generate from "./cmds/generate";
|
||||
import * as info from "./cmds/info";
|
||||
import * as near from "./cmds/near";
|
||||
import * as parse from "./cmds/parse";
|
||||
import * as recover from "./cmds/recover";
|
||||
import * as submit from "./cmds/submit";
|
||||
import * as sui from "./cmds/sui";
|
||||
import * as verifyVaa from "./cmds/verifyVaa";
|
||||
import * as status from "./cmds/status";
|
||||
import { CLI_COMMAND_MODULES } from "./cmds";
|
||||
|
||||
const MD_TAG = "<!--CLI_USAGE-->";
|
||||
|
||||
|
@ -24,24 +11,15 @@ async function getHelpText(cmd: any): Promise<string> {
|
|||
// Note that `yargs` is called as a function to produce a fresh copy.
|
||||
// Otherwise the imported module is effectively a singleton where state from
|
||||
// other commands is accumulated from repeat calls.
|
||||
return await cmd.builder(yargs()).scriptName(`worm ${cmd.command}`).getHelp();
|
||||
return await cmd
|
||||
.builder(yargs())
|
||||
.scriptName(`worm ${cmd.command}`)
|
||||
.locale("en") //NOTE: 'locale' needed to override auto-detected locale from the user’s operating system
|
||||
.getHelp();
|
||||
}
|
||||
|
||||
(async function () {
|
||||
const cmds = [
|
||||
aptos,
|
||||
editVaa,
|
||||
evm,
|
||||
generate,
|
||||
info,
|
||||
near,
|
||||
parse,
|
||||
recover,
|
||||
submit,
|
||||
sui,
|
||||
verifyVaa,
|
||||
status,
|
||||
];
|
||||
const cmds = CLI_COMMAND_MODULES;
|
||||
|
||||
const helpOutputs: Buffer[] = [];
|
||||
for (const cmd of cmds) {
|
||||
|
|
|
@ -4,38 +4,12 @@ import { hideBin } from "yargs/helpers";
|
|||
// Side effects are here to trigger before the afflicted libraries' on-import warnings can be emitted.
|
||||
// It is also imported so that it can side-effect without being tree-shaken.
|
||||
import "./side-effects";
|
||||
// https://github.com/yargs/yargs/blob/main/docs/advanced.md#example-command-hierarchy-using-indexmjs
|
||||
import * as aptos from "./cmds/aptos";
|
||||
import * as editVaa from "./cmds/editVaa";
|
||||
import * as evm from "./cmds/evm";
|
||||
import * as generate from "./cmds/generate";
|
||||
import * as info from "./cmds/info";
|
||||
import * as near from "./cmds/near";
|
||||
import * as parse from "./cmds/parse";
|
||||
import * as recover from "./cmds/recover";
|
||||
import * as submit from "./cmds/submit";
|
||||
import * as sui from "./cmds/sui";
|
||||
import * as transfer from "./cmds/transfer";
|
||||
import * as verifyVaa from "./cmds/verifyVaa";
|
||||
import * as status from "./cmds/status";
|
||||
import { YargsCommandModule } from "./cmds/Yargs";
|
||||
import { CLI_COMMAND_MODULES } from "./cmds";
|
||||
|
||||
// Note: When adding another subcommand here, please be sure to also include it
|
||||
// in the `cmds` array in `docs.ts` so it is properly documented.
|
||||
yargs(hideBin(process.argv))
|
||||
// https://github.com/yargs/yargs/blob/main/docs/advanced.md#commanddirdirectory-opts
|
||||
// can't use `.commandDir` because bundling + tree-shaking
|
||||
.command(aptos)
|
||||
.command(editVaa)
|
||||
.command(evm)
|
||||
.command(generate)
|
||||
.command(info)
|
||||
.command(near)
|
||||
.command(parse)
|
||||
.command(recover)
|
||||
.command(submit)
|
||||
.command(sui)
|
||||
.command(transfer)
|
||||
.command(verifyVaa)
|
||||
.command(status)
|
||||
// Build CLI commands dinamically from CLI_COMMAND_MODULES list
|
||||
// Documentation about command hierarchy can be found here: https://github.com/yargs/yargs/blob/main/docs/advanced.md#example-command-hierarchy-using-indexmjs
|
||||
.command(CLI_COMMAND_MODULES as YargsCommandModule[])
|
||||
.strict()
|
||||
.demandCommand().argv;
|
||||
|
|
Loading…
Reference in New Issue