Quickly build cool CLI apps in Rust.
cargo new --bin head
.Add quicli as an dependency in your Cargo.toml
:
toml
[dependencies]
quicli = "0.1"
Now, open up your src/main.rs
. First, let's import all the good stuff:
```rust
use quicli::prelude::*; ```
Now, quickly write a cool CLI (it's also okay to type slowly):
```rust // Add cool slogan for your app here, e.g.: /// Get first n lines of a file
struct Cli {
// Add a CLI argument --count
/-n` that defaults to 3, and has this help text:
/// How many lines to get
#[structopt(long = "count", short = "n", default_value = "3")]
count: usize,
// Add a positional argument that the user has to supply:
/// The file to read
file: String,
}
main!({ let args = Cli::fromargs(); let data = readfile(args.file)?; data.lines().take(args.count).for_each(|line| println!("{}", line)); }); ```
Give it a spin!
cargo run
it! Did you see a nice error?cargo run -- Cargo.toml
show you?cargo run -- Cargo.toml --count=4
or cargo run -- Cargo.toml -n 2
?cargo run -- --help
-- how cool is that?--cont 4
(with the missing u).This is only possible because of all the awesome libraries included here:
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.