Skip to content

Commit

Permalink
fix: restructure commands (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
JackHamer09 authored Oct 6, 2023
1 parent e980375 commit c83d1b5
Show file tree
Hide file tree
Showing 24 changed files with 115 additions and 83 deletions.
10 changes: 5 additions & 5 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Contributing to zkSync Era CLI
# Contributing to zkSync CLI

## Welcome! 🎉

Hello, contributor! Thanks for thinking about helping with the `zkSync Era CLI` project. This guide will help you understand how to contribute to our CLI tool.
Hello, contributor! Thanks for thinking about helping with the zkSync CLI project. This guide will help you understand how to contribute to our CLI tool.

## Getting Started

- **Fork the project.** First, fork the `zkSync Era CLI` repository to your GitHub account.
- **Fork the project.** First, fork the `zksync-cli` repository to your GitHub account.

- **Download the project.** Now, get the project on your computer:

Expand Down Expand Up @@ -41,7 +41,7 @@ Hello, contributor! Thanks for thinking about helping with the `zkSync Era CLI`
## Sending a Pull Request
- **Ask to add your changes.** Go to the `zkSync Era CLI` repository on GitHub. You'll see a button "Compare & pull request." Click it and tell us about your changes.
- **Ask to add your changes.** Go to the `zksync-cli` repository on GitHub. You'll see a button "Compare & pull request." Click it and tell us about your changes.

- **Wait for feedback.** Our team will look at your changes. We might ask you to change some things.

Expand All @@ -61,7 +61,7 @@ If you have questions, you can ask on our [zkSync Community Hub](https://github.
## Thank You!
After we add your changes to the `zkSync Era CLI` project, we'll be very thankful! Your help makes our project better.
After we add your changes to the `zksync-cli` project, we'll be very thankful! Your help makes our project better.

We hope you enjoy helping and come back to help more. Thanks for being part of our team!

Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ contact_links:
- name: zksync-developers Discussion
url: https://github.com/zkSync-Community-Hub/zkync-developers/discussions
about: Please provide feedback, and ask questions here.
- name: zksync-cli documentation page
- name: zkSync CLI documentation page
url: https://era.zksync.io/docs/tools/zksync-cli
about: Please refer to the documentation for immediate answers.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<div align="center">

# ‣ zkSync Era CLI
# ‣ zkSync CLI

![zksync cli](./zksync-cli-banner.png)
![zkSync CLI](./zksync-cli-banner.png)

This CLI tool simplifies the process of developing applications and interacting with zkSync Era.
This CLI tool simplifies the process of developing applications and interacting with zkSync.

[Documentation](https://era.zksync.io/docs/tools/zksync-cli) | [Report a bug](https://github.com/matter-labs/zksync-cli/issues/new) | [Request a feature](https://github.com/matter-labs/zksync-cli/issues/new)

Expand All @@ -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 `zksync-cli dev` commands)
- [Yarn](https://v3.yarnpkg.com/getting-started/install) (for `zksync-cli create-project`)
- [Yarn](https://v3.yarnpkg.com/getting-started/install) (for `zksync-cli create` commands)

## 📥 Usage

Expand All @@ -27,7 +27,7 @@ Or you can install the CLI globally with `npm i -g zksync-cli` and run the comma
## 💻 Commands

### Local development commands
`zksync-cli dev` - All-in-one tool for local zkSync development. It allows to easily start zkSync stack locally, for example: local Ethereum and zkSync nodes, Wallet and Bridge.
`zksync-cli dev` - Manage local zkSync development environment. It allows to easily start zkSync stack locally, for example: local Ethereum and zkSync nodes, Wallet and Bridge.

**General:**
- `zksync-cli dev start` - start local development environment (will ask to configure if starting for the first time)
Expand All @@ -44,16 +44,16 @@ In addition to default modules, you can install custom modules from NPM.
Run `zksync-cli dev` to see the full list of commands.

### Bridge commands
- `zksync-cli deposit`: deposits funds from Ethereum (L1) to zkSync (L2)
- `zksync-cli withdraw`: withdraws funds from zkSync (L2) to Ethereum (L1)
- `zksync-cli withdraw-finalize`: finalizes withdrawal of funds from zkSync (L2) to Ethereum (L1)
- `zksync-cli bridge deposit`: deposits funds from Ethereum (L1) to zkSync (L2)
- `zksync-cli bridge withdraw`: withdraws funds from zkSync (L2) to Ethereum (L1)
- `zksync-cli bridge withdraw-finalize`: finalizes withdrawal of funds from zkSync (L2) to Ethereum (L1)

### Create project commands
- `zksync-cli create-project {FOLDER_NAME}`: creates project from template in the specified folder
- `zksync-cli create project {FOLDER_NAME}`: creates project from template in the specified folder

### Other commands
- `zksync-cli help`: Provides information about all supported commands
- `zksync-cli 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)
- `zksync-cli 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`)
- `zksync-cli --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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "zksync-cli",
"type": "module",
"version": "0.0.0-development",
"description": "CLI tool that simplifies the process of developing applications and interacting with the zkSync Era network",
"description": "CLI tool that simplifies the process of developing applications and interacting with the zkSync network",
"repository": {
"type": "git",
"url": "https://github.com/matter-labs/zksync-cli.git"
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);
11 changes: 10 additions & 1 deletion src/commands/dev/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ const checkForUpdates = async (modules: Module[]) => {
str += chalk.gray(` - zksync-cli dev update ${module.package.name}`);
Logger.info(str);
}
if (modulesRequiringUpdates.length > 1) {
Logger.info(
chalk.gray(
`Update all modules: zksync-cli dev update ${modulesRequiringUpdates
.map(({ module }) => module.package.name)
.join(" ")}`
)
);
}
};

const showStartupInfo = async (modules: Module[]) => {
Expand Down Expand Up @@ -106,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);
Loading

0 comments on commit c83d1b5

Please sign in to comment.