Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README #94

Merged
merged 7 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 111 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,119 +1,160 @@
## cargo-leet - A leetcode local development assistant
# `cargo-leet` - A leetcode local development assistant

A program that given the link or slug to a leetcode problem,
creates a local file where you can develop and test your solution before post it back to leetcode.
The `cargo leet` program helps you streamline your workflow with LeetCode problem local file where you can develop and test your solution before post it back to leetcode.

## Help Messages
## Usage

### `cargo leet -h`
Below is a summary of how to use the various commands and options available in `cargo leet`.

### General Usage

```sh
cargo leet [OPTIONS] <COMMAND>
```
cargo-leet

Usage: cargo <COMMAND>
### Commands

Commands:
leet This is necessary because it's a cargo subcommand so the first argument needs to be the command name
help Print this message or the help of the given subcommand(s)
- **new**
Creates a new pre-configured project based on a template, which can be used with `cargo-leet`.

Options:
-h, --help Print help (see more with '--help')
```
```sh
cargo leet new [OPTIONS] [NAME]
```

### `cargo leet generate --help`
- **generate, -g, gen**
Generates a module for the specified problem, allowing you to start working on the solution locally. You can provide a LeetCode problem slug or URL, or leave it blank to use the daily challenge.

```
Usage: cargo leet {generate|-g} [OPTIONS] [PROBLEM]
```sh
cargo leet generate [OPTIONS] [PROBLEM]
```

Arguments:
[PROBLEM]
Question slug or url (If none specified then daily challenge is used)
- **active**
Prints the currently active problem or sets the active problem to the provided problem slug.

Options:
-n, --number_in_name
If set the module name generated includes the number for the problem
```sh
cargo leet active [OPTIONS] [PROBLEM_SLUG]
```

-p, --path <FOLDER>
Specify the path to the project root (If not provided uses current working directory)
- **test**
Runs tests on the currently active problem to verify your solution.

-l, --log-level <LOG_LEVEL>
Set logging level to use
```sh
cargo leet test [OPTIONS]
```

[default: warn]
### Options

Possible values:
- off: Nothing emitted in this mode
- error
- warn
- info
- debug
- trace
- **-p, --path \<FOLDER\>**
Specify the path to the project root. If not provided, the current working directory is used.
- **-l, --log-level \<LOG_LEVEL\>**
Set the logging level. Default is `warn`. Available levels:
- `off`: No logging
- `error`
- `warn`
- `info`
- `debug`
- `trace`
- **-h, --help**
Displays help information.
- **-V, --version**
Prints the version of `cargo leet`.

-h, --help
Print help (see a summary with '-h')
```
### Examples

## Using Library Support
- **Create a new project**:

Using the library to "mimic" leetcode environment. Add library as a dependency as below. Then add use statements as
necessary. The use statements are automatically added if tool is used to generate the file for the problem.
```sh
cargo leet new my-leetcode-project
```

```toml
cargo-leet = "0.2.0"
```
- **Change into the directory**

## Tool Installation
```sh
cd my-leetcode-project
```

NB: If cargo-leet is already installed, and you install it again, it will just replace it even if it was previously
installed from a different source. For example if you install it from a clone then run the command to install from git
it will replace the existing version that is installed (they will not both be installed).
- **Generate a module for a specific problem**:

### From GitHub
```sh
cargo leet generate two-sum
```

```sh
cargo install --git https://github.com/rust-practice/cargo-leet.git --branch main --features=tool
```
- **Set the active problem (done automatically by `cargo leet gen`)**:

### From Clone
```sh
cargo leet active two-sum
```

After cloning the repo run
- **Run tests on the active problem**:

```sh
cargo install --path . --features=tool
```
```sh
cargo leet test
```

## Installation

Note: If `cargo-leet` is already installed and you install it again, the existing installation will be replaced, even if it was originally installed from a different source. For instance, if you first install it from a local clone and then reinstall it from a Git repository, the new installation will overwrite the previous one (you won't have both versions installed).

### Build from Source

or using alias from `.cargo/config.toml`
You can build `cargo-leet` from source using two different channels:

- **Stable (main)**

```sh
cargo install --git https://github.com/rust-practice/cargo-leet.git --branch main -F tool
```

This installs the stable version of `cargo-leet` from the `main` branch.

- **Development (develop)**
```sh
cargo install --git https://github.com/rust-practice/cargo-leet.git --branch develop -F tool
```
This installs the latest development version from the `develop` branch, which may include new features or changes that are still being tested.

### Install from crates.io

You can also install `cargo-leet` directly from crates.io. However, please note that the crates.io release may not always reflect the latest updates.

```sh
cargo i
cargo install cargo-leet -F tool
```

## Running Directly from source without install (When developing the tool)
### Running Directly from Source without Installation (For Development)

When developing the tool, you can run it directly from the source code without needing to install it. By default, these commands will execute the tool within the current working directory, meaning it will interact with the current project folder for `cargo-leet`.

These commands allow you to run the tool directly from the source code without installation.
By default, they will run the tool on the current working directory.
This means that it will run in the current project folder for cargo-leet.
This may be fine for testing but if you want to be able to actually run the code, it might be more appropriate to pass
the path parameter and specify the path to the repository you want to run against.
Eg. `cargo g --path $TEST_REPO`
For more options see [generate help](#cargo-leet-generate---help)
#### Running in the Current Directory

Running the tool this way is useful for testing but may not be ideal if you need to target a specific project or repository. In such cases, you can specify the path to the desired repository using the `--path` option.

For example, to run the tool against a specific test repository:

```sh
cargo run --features=tool -- leet gen
cargo run -F tool -- leet gen --path $TEST_REPO
```

or using alias from `.cargo/config.toml`
#### Using an Alias

If you have an alias configured in `.cargo/config.toml`, you can simplify the command:

```sh
cargo g
```

## Tool Uninstallation
For additional options and usage details, refer to the generate help in [commands](#commands).

## Using as a Library

You can use `cargo-leet` as a library to mimic the LeetCode environment in your own projects. To do so, add it as a dependency in your `Cargo.toml` file using

```sh
cargo uninstall cargo-leet
cargo add cargo-leet
```

For more information, see [the documentation](https://docs.rs/cargo-leet/).

## License

All code in this repository is dual-licensed under either:
Expand Down
4 changes: 2 additions & 2 deletions src/tool/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use log::{debug, info, LevelFilter};
#[command(name = "cargo")]
#[command(bin_name = "cargo")]
pub enum TopLevel {
/// This is necessary because it's a cargo subcommand so the first argument
/// needs to be the command name
// This is necessary because it's a cargo subcommand so the first argument needs to be the command name
/// A program that given the link or slug to a leetcode problem, creates a local file where you can develop and test your solution before post it back to leetcode.
Leet(Cli),
}

Expand Down