From af52a4acac1684637f18283ce02fc5ca1cd1db9a Mon Sep 17 00:00:00 2001 From: Jack Hamer Date: Fri, 6 Oct 2023 14:31:07 +0300 Subject: [PATCH] fix: restructure commands and improve wording --- README.md | 14 +++++------ src/commands/bridge/command.ts | 3 +++ src/commands/{ => bridge}/deposit.ts | 24 +++++++++---------- src/commands/bridge/index.ts | 5 ++++ .../{ => bridge}/withdraw-finalize.ts | 22 ++++++++--------- src/commands/{ => bridge}/withdraw.ts | 24 +++++++++---------- src/commands/create/command.ts | 3 +++ .../{create-project.ts => create/create.ts} | 22 ++++++++--------- src/commands/create/index.ts | 3 +++ src/commands/dev/clean.ts | 2 +- src/commands/dev/command.ts | 2 +- src/commands/dev/install.ts | 2 +- src/commands/dev/logs.ts | 2 +- src/commands/dev/modules/index.ts | 2 +- src/commands/dev/restart.ts | 2 +- src/commands/dev/start.ts | 2 +- src/commands/dev/stop.ts | 2 +- src/commands/dev/uninstall.ts | 2 +- src/commands/dev/update.ts | 2 +- src/index.ts | 8 +++---- 20 files changed, 81 insertions(+), 67 deletions(-) create mode 100644 src/commands/bridge/command.ts rename src/commands/{ => bridge}/deposit.ts (87%) create mode 100644 src/commands/bridge/index.ts rename src/commands/{ => bridge}/withdraw-finalize.ts (89%) rename src/commands/{ => bridge}/withdraw.ts (87%) create mode 100644 src/commands/create/command.ts rename src/commands/{create-project.ts => create/create.ts} (81%) create mode 100644 src/commands/create/index.ts diff --git a/README.md b/README.md index de359d06..074866cb 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ This CLI tool simplifies the process of developing applications and interacting - [Node.js v18 or higher](https://nodejs.org/en) - [Git](https://git-scm.com/downloads) - [Docker](https://www.docker.com/get-started/) (for `zkcli dev` commands) -- [Yarn](https://v3.yarnpkg.com/getting-started/install) (for `zkcli create-project`) +- [Yarn](https://v3.yarnpkg.com/getting-started/install) (for `zkcli create` commands) ## 📥 Usage @@ -44,16 +44,16 @@ In addition to default modules, you can install custom modules from NPM. Run `zkcli dev` to see the full list of commands. ### Bridge commands -- `zkcli deposit`: deposits funds from Ethereum (L1) to zkSync (L2) -- `zkcli withdraw`: withdraws funds from zkSync (L2) to Ethereum (L1) -- `zkcli withdraw-finalize`: finalizes withdrawal of funds from zkSync (L2) to Ethereum (L1) +- `zkcli bridge deposit`: deposits funds from Ethereum (L1) to zkSync (L2) +- `zkcli bridge withdraw`: withdraws funds from zkSync (L2) to Ethereum (L1) +- `zkcli bridge withdraw-finalize`: finalizes withdrawal of funds from zkSync (L2) to Ethereum (L1) ### Create project commands -- `zkcli create-project {FOLDER_NAME}`: creates project from template in the specified folder +- `zkcli create project {FOLDER_NAME}`: creates project from template in the specified folder ### Other commands - `zkcli help`: Provides information about all supported commands -- `zkcli help `: Provides detailed information about how to use a specific command. Replace with the name of the command you want help with (e.g., create-project, deposit, withdraw, withdraw-finalize) +- `zkcli help `: Provides detailed information about how to use a specific command. Replace with the name of the command you want help with (e.g., `create`, `dev config`, `bridge withdraw-finalize`) - `zkcli --version`: Returns the current version @@ -68,7 +68,7 @@ If you're using [local setup (dockerized testing node)](https://github.com/matte ### Run in development mode 1. Install all dependencies with `npm i`. -2. To use CLI in development mode run `npm run dev -- [command] [options]` (eg. `npm run dev -- deposit --chain=era-testnet`). +2. To use CLI in development mode run `npm run dev -- [command] [options]` (eg. `npm run dev -- bridge deposit --chain=era-testnet`). ### Building for production diff --git a/src/commands/bridge/command.ts b/src/commands/bridge/command.ts new file mode 100644 index 00000000..d00b3b7c --- /dev/null +++ b/src/commands/bridge/command.ts @@ -0,0 +1,3 @@ +import Program from "../../program.js"; + +export default Program.command("bridge").description("Bridge operations for zkSync"); diff --git a/src/commands/deposit.ts b/src/commands/bridge/deposit.ts similarity index 87% rename from src/commands/deposit.ts rename to src/commands/bridge/deposit.ts index 874751fb..89212876 100644 --- a/src/commands/deposit.ts +++ b/src/commands/bridge/deposit.ts @@ -1,5 +1,6 @@ import inquirer from "inquirer"; +import Program from "./command.js"; import { amountOptionCreate, chainOption, @@ -8,24 +9,23 @@ import { privateKeyOption, recipientOptionCreate, zeekOption, -} from "../common/options.js"; -import { l2Chains } from "../data/chains.js"; -import Program from "../program.js"; -import { track } from "../utils/analytics.js"; -import { ETH_TOKEN } from "../utils/constants.js"; -import { bigNumberToDecimal, decimalToBigNumber } from "../utils/formatters.js"; +} from "../../common/options.js"; +import { l2Chains } from "../../data/chains.js"; +import { track } from "../../utils/analytics.js"; +import { ETH_TOKEN } from "../../utils/constants.js"; +import { bigNumberToDecimal, decimalToBigNumber } from "../../utils/formatters.js"; import { getAddressFromPrivateKey, getL1Provider, getL2Provider, getL2Wallet, optionNameToParam, -} from "../utils/helpers.js"; -import Logger from "../utils/logger.js"; -import { isDecimalAmount, isAddress, isPrivateKey } from "../utils/validators.js"; -import zeek from "../utils/zeek.js"; +} from "../../utils/helpers.js"; +import Logger from "../../utils/logger.js"; +import { isDecimalAmount, isAddress, isPrivateKey } from "../../utils/validators.js"; +import zeek from "../../utils/zeek.js"; -import type { DefaultTransferOptions } from "../common/options.js"; +import type { DefaultTransferOptions } from "../../common/options.js"; const amountOption = amountOptionCreate("deposit"); const recipientOption = recipientOptionCreate("L2"); @@ -135,7 +135,7 @@ export const handler = async (options: DepositOptions) => { }; Program.command("deposit") - .description("Deposit ETH from L1 to L2") + .description("Transfer ETH from L1 to L2") .addOption(amountOption) .addOption(chainOption) .addOption(recipientOption) diff --git a/src/commands/bridge/index.ts b/src/commands/bridge/index.ts new file mode 100644 index 00000000..d66ea062 --- /dev/null +++ b/src/commands/bridge/index.ts @@ -0,0 +1,5 @@ +import "./deposit.js"; +import "./withdraw.js"; +import "./withdraw-finalize.js"; + +import "./command.js"; // registers all the commands above diff --git a/src/commands/withdraw-finalize.ts b/src/commands/bridge/withdraw-finalize.ts similarity index 89% rename from src/commands/withdraw-finalize.ts rename to src/commands/bridge/withdraw-finalize.ts index 7ddb6d36..eaf7dc4f 100644 --- a/src/commands/withdraw-finalize.ts +++ b/src/commands/bridge/withdraw-finalize.ts @@ -1,23 +1,23 @@ import { Option } from "commander"; import inquirer from "inquirer"; -import { chainOption, l1RpcUrlOption, l2RpcUrlOption, privateKeyOption, zeekOption } from "../common/options.js"; -import { l2Chains } from "../data/chains.js"; -import Program from "../program.js"; -import { track } from "../utils/analytics.js"; -import { bigNumberToDecimal } from "../utils/formatters.js"; +import Program from "./command.js"; +import { chainOption, l1RpcUrlOption, l2RpcUrlOption, privateKeyOption, zeekOption } from "../../common/options.js"; +import { l2Chains } from "../../data/chains.js"; +import { track } from "../../utils/analytics.js"; +import { bigNumberToDecimal } from "../../utils/formatters.js"; import { getAddressFromPrivateKey, getL1Provider, getL2Provider, getL2Wallet, optionNameToParam, -} from "../utils/helpers.js"; -import Logger from "../utils/logger.js"; -import { isPrivateKey, isTransactionHash } from "../utils/validators.js"; -import zeek from "../utils/zeek.js"; +} from "../../utils/helpers.js"; +import Logger from "../../utils/logger.js"; +import { isPrivateKey, isTransactionHash } from "../../utils/validators.js"; +import zeek from "../../utils/zeek.js"; -import type { DefaultTransactionOptions } from "../common/options.js"; +import type { DefaultTransactionOptions } from "../../common/options.js"; const transactionHashOption = new Option("--hash ", "L2 withdrawal transaction hash to finalize"); @@ -133,7 +133,7 @@ export const handler = async (options: WithdrawFinalizeOptions) => { }; Program.command("withdraw-finalize") - .description("Finalizes withdrawal of funds") + .description("Finalize withdrawal of funds") .addOption(transactionHashOption) .addOption(chainOption) .addOption(l1RpcUrlOption) diff --git a/src/commands/withdraw.ts b/src/commands/bridge/withdraw.ts similarity index 87% rename from src/commands/withdraw.ts rename to src/commands/bridge/withdraw.ts index fd148508..5e48742b 100644 --- a/src/commands/withdraw.ts +++ b/src/commands/bridge/withdraw.ts @@ -1,5 +1,6 @@ import inquirer from "inquirer"; +import Program from "./command.js"; import { amountOptionCreate, chainOption, @@ -8,24 +9,23 @@ import { privateKeyOption, recipientOptionCreate, zeekOption, -} from "../common/options.js"; -import { l2Chains } from "../data/chains.js"; -import Program from "../program.js"; -import { track } from "../utils/analytics.js"; -import { ETH_TOKEN } from "../utils/constants.js"; -import { bigNumberToDecimal, decimalToBigNumber } from "../utils/formatters.js"; +} from "../../common/options.js"; +import { l2Chains } from "../../data/chains.js"; +import { track } from "../../utils/analytics.js"; +import { ETH_TOKEN } from "../../utils/constants.js"; +import { bigNumberToDecimal, decimalToBigNumber } from "../../utils/formatters.js"; import { getAddressFromPrivateKey, getL1Provider, getL2Provider, getL2Wallet, optionNameToParam, -} from "../utils/helpers.js"; -import Logger from "../utils/logger.js"; -import { isDecimalAmount, isAddress, isPrivateKey } from "../utils/validators.js"; -import zeek from "../utils/zeek.js"; +} from "../../utils/helpers.js"; +import Logger from "../../utils/logger.js"; +import { isDecimalAmount, isAddress, isPrivateKey } from "../../utils/validators.js"; +import zeek from "../../utils/zeek.js"; -import type { DefaultTransferOptions } from "../common/options.js"; +import type { DefaultTransferOptions } from "../../common/options.js"; const amountOption = amountOptionCreate("withdraw"); const recipientOption = recipientOptionCreate("L1"); @@ -135,7 +135,7 @@ export const handler = async (options: WithdrawOptions) => { }; Program.command("withdraw") - .description("Withdraw ETH from L2 to L1") + .description("Transfer ETH from L2 to L1") .addOption(amountOption) .addOption(chainOption) .addOption(recipientOption) diff --git a/src/commands/create/command.ts b/src/commands/create/command.ts new file mode 100644 index 00000000..b52074c2 --- /dev/null +++ b/src/commands/create/command.ts @@ -0,0 +1,3 @@ +import Program from "../../program.js"; + +export default Program.command("create").description("Scaffold new project for zkSync"); diff --git a/src/commands/create-project.ts b/src/commands/create/create.ts similarity index 81% rename from src/commands/create-project.ts rename to src/commands/create/create.ts index 48e0d3eb..019ecb23 100644 --- a/src/commands/create-project.ts +++ b/src/commands/create/create.ts @@ -2,14 +2,14 @@ import { Option } from "commander"; import inquirer from "inquirer"; import path from "path"; -import { zeekOption } from "../common/options.js"; -import Program from "../program.js"; -import { track } from "../utils/analytics.js"; -import { optionNameToParam, executeCommand } from "../utils/helpers.js"; -import Logger from "../utils/logger.js"; -import zeek from "../utils/zeek.js"; +import Program from "./command.js"; +import { zeekOption } from "../../common/options.js"; +import { track } from "../../utils/analytics.js"; +import { optionNameToParam, executeCommand } from "../../utils/helpers.js"; +import Logger from "../../utils/logger.js"; +import zeek from "../../utils/zeek.js"; -import type { DefaultOptions } from "../common/options.js"; +import type { DefaultOptions } from "../../common/options.js"; const templates = [ { @@ -39,7 +39,7 @@ export const handler = async (folderName: string, options: CreateOptions) => { ...options, folderName, }; - Logger.debug(`Initial create-project options: ${JSON.stringify(options, null, 2)}`); + Logger.debug(`Initial create project options: ${JSON.stringify(options, null, 2)}`); const answers: CreateOptions = await inquirer.prompt( [ @@ -59,7 +59,7 @@ export const handler = async (folderName: string, options: CreateOptions) => { ...answers, }; - Logger.debug(`Final create-project options: ${JSON.stringify(options, null, 2)}`); + Logger.debug(`Final create project options: ${JSON.stringify(options, null, 2)}`); const template = templates.find((e) => e.value === options.template)!; @@ -95,9 +95,9 @@ Read the ${path.join(options.folderName!, "README.md")} file to learn more. } }; -Program.command("create-project") +Program.command("project") + .description("Initiate a project using a template in the chosen folder") .argument("", "Folder name to create project in") - .description("Creates project from template in the specified folder") .addOption(templateOption) .addOption(zeekOption) .action(handler); diff --git a/src/commands/create/index.ts b/src/commands/create/index.ts new file mode 100644 index 00000000..b8bbf9fe --- /dev/null +++ b/src/commands/create/index.ts @@ -0,0 +1,3 @@ +import "./create.js"; + +import "./command.js"; // registers all the commands above diff --git a/src/commands/dev/clean.ts b/src/commands/dev/clean.ts index 67d5ba49..8cee763a 100644 --- a/src/commands/dev/clean.ts +++ b/src/commands/dev/clean.ts @@ -31,4 +31,4 @@ export const handler = async () => { } }; -Program.command("clean").description("Cleans data for all config modules").action(handler); +Program.command("clean").description("Clean data for all config modules").action(handler); diff --git a/src/commands/dev/command.ts b/src/commands/dev/command.ts index ef05a28f..119a79f0 100644 --- a/src/commands/dev/command.ts +++ b/src/commands/dev/command.ts @@ -1,3 +1,3 @@ import Program from "../../program.js"; -export default Program.command("dev").description("All-in-one tool for local zkSync development"); +export default Program.command("dev").description("Manage local zkSync development environment"); diff --git a/src/commands/dev/install.ts b/src/commands/dev/install.ts index f52c8245..9bbf59db 100644 --- a/src/commands/dev/install.ts +++ b/src/commands/dev/install.ts @@ -31,7 +31,7 @@ export const handler = async (moduleNames: string[], options: { link: boolean }) Program.command("install") .alias("i") - .argument("[module...]", "NPM package name of the module to install") .description("Install module with NPM") + .argument("", "NPM package name of the module to install") .addOption(linkOption) .action(handler); diff --git a/src/commands/dev/logs.ts b/src/commands/dev/logs.ts index 52b575ed..9ce6a941 100644 --- a/src/commands/dev/logs.ts +++ b/src/commands/dev/logs.ts @@ -38,4 +38,4 @@ export const handler = async () => { } }; -Program.command("logs").description("Displays logs for configured modules").action(handler); +Program.command("logs").description("Show logs for configured modules").action(handler); diff --git a/src/commands/dev/modules/index.ts b/src/commands/dev/modules/index.ts index 906e5c91..e02b451d 100644 --- a/src/commands/dev/modules/index.ts +++ b/src/commands/dev/modules/index.ts @@ -34,4 +34,4 @@ export const handler = async () => { } }; -Program.command("modules").description("Displays list of installed modules").action(handler); +Program.command("modules").description("List currently installed modules").action(handler); diff --git a/src/commands/dev/restart.ts b/src/commands/dev/restart.ts index 6b0fe0d6..57f8b347 100644 --- a/src/commands/dev/restart.ts +++ b/src/commands/dev/restart.ts @@ -15,4 +15,4 @@ export const handler = async () => { } }; -Program.command("restart").description("Restarts the local zkSync environment and modules").action(handler); +Program.command("restart").description("Restart local zkSync environment and modules").action(handler); diff --git a/src/commands/dev/start.ts b/src/commands/dev/start.ts index d388277e..a68b6631 100644 --- a/src/commands/dev/start.ts +++ b/src/commands/dev/start.ts @@ -115,4 +115,4 @@ export const handler = async () => { } }; -Program.command("start").description("Starts the local zkSync environment and modules").action(handler); +Program.command("start").description("Start local zkSync environment and modules").action(handler); diff --git a/src/commands/dev/stop.ts b/src/commands/dev/stop.ts index de888a5a..a946fbc4 100644 --- a/src/commands/dev/stop.ts +++ b/src/commands/dev/stop.ts @@ -15,4 +15,4 @@ export const handler = async () => { } }; -Program.command("stop").description("Stops the local zkSync environment and modules").action(handler); +Program.command("stop").description("Stop local zkSync environment and modules").action(handler); diff --git a/src/commands/dev/uninstall.ts b/src/commands/dev/uninstall.ts index a309a983..8068b56d 100644 --- a/src/commands/dev/uninstall.ts +++ b/src/commands/dev/uninstall.ts @@ -39,7 +39,7 @@ export const handler = async (moduleNames: string[], options: { unlink: boolean }; Program.command("uninstall") - .argument("[module...]", "NPM package name of the module to uninstall") .description("Uninstall module with NPM") + .argument("", "NPM package name of the module to uninstall") .addOption(unlinkOption) .action(handler); diff --git a/src/commands/dev/update.ts b/src/commands/dev/update.ts index 9043ec57..c4460ca8 100644 --- a/src/commands/dev/update.ts +++ b/src/commands/dev/update.ts @@ -72,8 +72,8 @@ export const handler = async (moduleNames: string[], options: ModuleUpdateOption }; Program.command("update") + .description("Update module version") .argument("", "NPM package name of the module to update") - .description("Update installed module") .addOption(forceOption) .addOption(packageOption) .action(handler); diff --git a/src/index.ts b/src/index.ts index 32583f07..2a37bec9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,9 +2,9 @@ import Program from "./program.js"; import "./commands/dev/index.js"; -import "./commands/deposit.js"; -import "./commands/withdraw.js"; -import "./commands/withdraw-finalize.js"; -import "./commands/create-project.js"; + +import "./commands/bridge/index.js"; + +import "./commands/create/index.js"; Program.parse();