Skip to content

Commit

Permalink
Merge pull request #21 from dutterbutter/db/update-help-cmd
Browse files Browse the repository at this point in the history
feat: adds command --help
  • Loading branch information
uF4No authored Jul 28, 2023
2 parents f58f757 + d071d62 commit 93e28eb
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ artifacts

bin
bin/
bin/*.js
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <command> --help`: 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, deposit, withdraw, confirm-withdraw).

> Both deposit and withdraw might take a couple of minutes to complete.

Expand Down
15 changes: 15 additions & 0 deletions src/confirm-withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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=<URL> --l2-rpc-url=<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=<URL>`));
console.log(`The URL of the L1 RPC provider.\n`);
console.log(chalk.greenBright(`--l2-rpc-url=<URL>`));
console.log(`The URL of the L2 RPC provider.\n`);
}

export default async function (
zeek?: boolean,
l1RpcUrl?: string,
Expand Down
10 changes: 10 additions & 0 deletions src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <project_name>\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 = [
{
Expand Down
24 changes: 18 additions & 6 deletions src/deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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=<URL> --l2-rpc-url=<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=<URL>`));
console.log(`The URL of the L1 RPC provider.\n`);
console.log(chalk.greenBright(`--l2-rpc-url=<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 = [
{
Expand Down
67 changes: 44 additions & 23 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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}`
Expand Down Expand Up @@ -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) {
Expand Down
24 changes: 18 additions & 6 deletions src/withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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=<URL> --l2-rpc-url=<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=<URL>`));
console.log(`The URL of the L1 RPC provider.\n`);
console.log(chalk.greenBright(`--l2-rpc-url=<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 = [
{
Expand Down

0 comments on commit 93e28eb

Please sign in to comment.