Build
To create a binary, use:
cargo build --release
If you want to customize the name, add [[bin]]
section into Cargo.toml
:
[[bin]]
name = "grustep"
path = "src/main.rs"
It produces a file named grustep
in your project's target/release
directory.
To install the binary to the system's cargo bin directory, you can use this:
cargo install --path .
After installation, you can do this:
grustep -n result src/main.rs
You should be able to see something similar to this:
27: let result = if matches.is_present("recursive") {
33: match result {
34: Ok(result) => {
36: println!("{}", grep_count(&result));
38: print_result(&result, matches.is_present("line-number"))
47: fn print_result(result: &MatchResult, show_line_number: bool) {
49: let file_count = result.len();
51: for (file_path, items) in result {
At this point, you have a bunch of commands (run, test, lint and etc) to remember. Just add a Makefile to make it easier.
Makefile:
.PHONY: run test clean
run:
cargo run -- -rn result .
test:
cargo test
lint:
cargo clippy
install:
cargo install --path .
build:
cargo build --release
clean:
rm -rf target/
Then you can easily do these operations:
make run
make test
make build
make install