diff --git a/.gitignore b/.gitignore index ac32d116..5e974217 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ artifacts bin bin/ +bin/*.js \ No newline at end of file diff --git a/README.md b/README.md index 4fec1f20..d0b913a2 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,8 @@ You can install this program globally with `npm i -g zksync-cli` or run the comm - `zksync-cli confirm-withdrawal`: confirms withdrawal of funds from zkSync 2.0 to L1 (Goerli testnet). It will ask to enter: network, withdrawal transaction address and the private key of the wallet you sent the funds from. +- `zksync-cli --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, deposit, withdraw, confirm-withdraw). + > Both deposit and withdraw might take a couple of minutes to complete. diff --git a/src/confirm-withdraw.ts b/src/confirm-withdraw.ts index fd259baf..3b11b812 100644 --- a/src/confirm-withdraw.ts +++ b/src/confirm-withdraw.ts @@ -4,6 +4,21 @@ import chalk from "chalk"; import inquirer, { Answers, QuestionCollection } from "inquirer"; import { track } from "./analytics"; +// Used for `zksync-cli confirm-withdraw --help` +export const help = () => { + console.log(chalk.bold("Usage:")); + console.log("zksync-cli confirm-withdraw --l1-rpc-url= --l2-rpc-url=\n"); + console.log(chalk.bold(`Description:`)); + console.log( + `Confirms the withdrawal of funds from zkSync to L1. The command will ask for the network, the zkSync transaction address, and the sender's private key.\n` + ); + console.log(chalk.bold(`Options:`)); + console.log(chalk.greenBright(`--l1-rpc-url=`)); + console.log(`The URL of the L1 RPC provider.\n`); + console.log(chalk.greenBright(`--l2-rpc-url=`)); + console.log(`The URL of the L2 RPC provider.\n`); +} + export default async function ( zeek?: boolean, l1RpcUrl?: string, diff --git a/src/create.ts b/src/create.ts index 991df54f..138bf6a2 100644 --- a/src/create.ts +++ b/src/create.ts @@ -19,6 +19,16 @@ const runCommand = (command: string) => { return true; }; +// Used for `zksync-cli create --help` +export const help = () => { + console.log(chalk.bold("Usage:")); + console.log("zksync-cli create \n"); + console.log(chalk.bold(`Description:`)); + console.log( + `Creates a new Hardhat project in the provided folder. If no folder is specified, it will create the project in the current folder, provided it's empty.\n` + ); +} + export default async function (projectName: string, zeek?: boolean) { const questions: QuestionCollection = [ { diff --git a/src/deposit.ts b/src/deposit.ts index 7ed09692..fe68e4fa 100644 --- a/src/deposit.ts +++ b/src/deposit.ts @@ -5,12 +5,24 @@ import chalk from "chalk"; import inquirer, { Answers, QuestionCollection } from "inquirer"; import { track } from "./analytics"; -export default async function ( - zeek?: boolean, - l1RpcUrl?: string, - l2RpcUrl?: string -) { - console.log(chalk.magentaBright("Deposit funds from L1 to zkSync Era")); +// Used for `zksync-cli deposit --help` +export const help = () => { + console.log(chalk.bold("Usage:")); + console.log("zksync-cli deposit --l1-rpc-url= --l2-rpc-url=\n"); + console.log(chalk.bold(`Description:`)); + console.log( + `Deposits funds from L1 to L2. The command will ask for the network, the recipient's address, the amount in ETH, and the sender's private key.\n` + ); + console.log(chalk.bold(`Options:`)); + console.log(chalk.greenBright(`--l1-rpc-url=`)); + console.log(`The URL of the L1 RPC provider.\n`); + console.log(chalk.greenBright(`--l2-rpc-url=`)); + console.log(`The URL of the L2 RPC provider.\n`); +} + +export default async function (zeek?: boolean, l1RpcUrl?: string, l2RpcUrl?: string) { + + console.log(chalk.magentaBright("Deposit funds from L1 to zkSync")); const questions: QuestionCollection = [ { diff --git a/src/index.ts b/src/index.ts index 7c55b93f..2e097b50 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,12 +7,12 @@ import chalk from "chalk"; import figlet from "figlet"; // import method to create projects -import create from "./create"; -import deposit from "./deposit"; -import withdraw from "./withdraw"; -import help from "./help"; -import confirmWithdraw from "./confirm-withdraw"; +import create, { help as createHelp } from "./create"; +import deposit, { help as depositHelp } from "./deposit"; +import withdraw, { help as withdrawHelp } from "./withdraw"; +import confirmWithdraw, { help as confirmWithdrawalHelp } from "./confirm-withdraw"; import zeek from "./zeek"; +import help from "./help"; const availableOptions: string[] = [ "create", @@ -26,6 +26,7 @@ const availableOptions: string[] = [ const option: string = process.argv[2]; const main = async () => { + const helpFlag = Boolean(process.argv.filter((arg) => ["--help", "-h"].includes(arg))[0]); if (!availableOptions.includes(option)) { console.log( `Invalid operation. Available operations are: ${availableOptions}` @@ -53,24 +54,44 @@ const main = async () => { .map((arg) => arg.split("=")[1])[0] ); - switch (option) { - case "create": - // arg 3 is the project name - const projectName = process.argv[3] || "."; - await create(projectName, zeekFlag); - break; - case "deposit": - await deposit(zeekFlag, l1RpcUrl, l2RpcUrl); - break; - case "withdraw": - await withdraw(zeekFlag, l1RpcUrl, l2RpcUrl); - break; - case "confirm-withdraw": - await confirmWithdraw(zeekFlag, l1RpcUrl, l2RpcUrl); - break; - case "help": - help(); - break; + if (helpFlag) { + switch (option) { + case "create": + createHelp(); + break; + case "deposit": + depositHelp(); + break; + case "withdraw": + withdrawHelp(); + break; + case "confirm-withdraw": + confirmWithdrawalHelp(); + break; + default: + help(); + break; + } + } else { + switch (option) { + case "create": + // arg 3 is the project name + const projectName = process.argv[3] || "."; + await create(projectName, zeekFlag); + break; + case "deposit": + await deposit(zeekFlag, l1RpcUrl, l2RpcUrl); + break; + case "withdraw": + await withdraw(zeekFlag, l1RpcUrl, l2RpcUrl); + break; + case "confirm-withdraw": + await confirmWithdraw(zeekFlag, l1RpcUrl, l2RpcUrl); + break; + case "help": + help(); + break; + } } if (zeekFlag) { diff --git a/src/withdraw.ts b/src/withdraw.ts index 09cd8fde..f96307a0 100644 --- a/src/withdraw.ts +++ b/src/withdraw.ts @@ -4,12 +4,24 @@ import chalk from "chalk"; import inquirer, { Answers, QuestionCollection } from "inquirer"; import { track } from "./analytics"; -export default async function ( - zeek?: boolean, - l1RpcUrl?: string, - l2RpcUrl?: string -) { - console.log(chalk.magentaBright("Withdraw funds from zkSync to Goerli")); +// Used for `zksync-cli withdraw --help` +export const help = () => { + console.log(chalk.bold("Usage:")); + console.log("zksync-cli withdraw --l1-rpc-url= --l2-rpc-url=\n"); + console.log(chalk.bold(`Description:`)); + console.log( + `Withdraws funds from L2 to L1. The command will ask for the network, the recipient's address, the amount in ETH, and the sender's private key.\n` + ); + console.log(chalk.bold(`Options:`)); + console.log(chalk.greenBright(`--l1-rpc-url=`)); + console.log(`The URL of the L1 RPC provider.\n`); + console.log(chalk.greenBright(`--l2-rpc-url=`)); + console.log(`The URL of the L2 RPC provider.\n`); +} + +export default async function (zeek?: boolean, l1RpcUrl?: string, l2RpcUrl?: string) { + + console.log(chalk.magentaBright('Withdraw funds from zkSync to Goerli')); const questions: QuestionCollection = [ {