Skip to content

Commit

Permalink
fix: restructure commands and improve wording
Browse files Browse the repository at this point in the history
  • Loading branch information
JackHamer09 committed Oct 6, 2023
1 parent bcfecb5 commit af52a4a
Show file tree
Hide file tree
Showing 20 changed files with 81 additions and 67 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 <command>`: Provides detailed information about how to use a specific command. Replace <command> with the name of the command you want help with (e.g., create-project, deposit, withdraw, withdraw-finalize)
- `zkcli help <command>`: Provides detailed information about how to use a specific command. Replace <command> with the name of the command you want help with (e.g., `create`, `dev config`, `bridge withdraw-finalize`)
- `zkcli --version`: Returns the current version


Expand All @@ -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

Expand Down
3 changes: 3 additions & 0 deletions src/commands/bridge/command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Program from "../../program.js";

export default Program.command("bridge").description("Bridge operations for zkSync");
24 changes: 12 additions & 12 deletions src/commands/deposit.ts → src/commands/bridge/deposit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import inquirer from "inquirer";

import Program from "./command.js";
import {
amountOptionCreate,
chainOption,
Expand All @@ -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");
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/commands/bridge/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import "./deposit.js";
import "./withdraw.js";
import "./withdraw-finalize.js";

import "./command.js"; // registers all the commands above
Original file line number Diff line number Diff line change
@@ -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 <transaction_hash>", "L2 withdrawal transaction hash to finalize");

Expand Down Expand Up @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions src/commands/withdraw.ts → src/commands/bridge/withdraw.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import inquirer from "inquirer";

import Program from "./command.js";
import {
amountOptionCreate,
chainOption,
Expand All @@ -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");
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/commands/create/command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Program from "../../program.js";

export default Program.command("create").description("Scaffold new project for zkSync");
22 changes: 11 additions & 11 deletions src/commands/create-project.ts → src/commands/create/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -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(
[
Expand All @@ -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)!;

Expand Down Expand Up @@ -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>", "Folder name to create project in")
.description("Creates project from template in the specified folder")
.addOption(templateOption)
.addOption(zeekOption)
.action(handler);
3 changes: 3 additions & 0 deletions src/commands/create/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import "./create.js";

import "./command.js"; // registers all the commands above
2 changes: 1 addition & 1 deletion src/commands/dev/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion src/commands/dev/command.ts
Original file line number Diff line number Diff line change
@@ -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");
2 changes: 1 addition & 1 deletion src/commands/dev/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("<module...>", "NPM package name of the module to install")
.addOption(linkOption)
.action(handler);
2 changes: 1 addition & 1 deletion src/commands/dev/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion src/commands/dev/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion src/commands/dev/restart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion src/commands/dev/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion src/commands/dev/stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion src/commands/dev/uninstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("<module...>", "NPM package name of the module to uninstall")
.addOption(unlinkOption)
.action(handler);
2 changes: 1 addition & 1 deletion src/commands/dev/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export const handler = async (moduleNames: string[], options: ModuleUpdateOption
};

Program.command("update")
.description("Update module version")
.argument("<module...>", "NPM package name of the module to update")
.description("Update installed module")
.addOption(forceOption)
.addOption(packageOption)
.action(handler);
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit af52a4a

Please sign in to comment.