other languages
why this ?
For a long time, developing cli in Rust
is difficult.
The community offers a wide range of solutions. Yes, they're excellent, but they're not very simple.
Inspired by commander.js & rocket.rs, the crate was born.
features
- API friendly
- easy to use
- support for approximate dynamic language
- low performance loss
- automatically support for
--version
&--help
- automatically run corresponding commands
limit
If you want to use this crate, please guarantee that you have follow rules below:
- using
Rust 2018
(full proc macro support is required, including [proc_macro] & [proc_macro_attribute]) - using
cargo
(cargo
will produce some environment variable according toCargo.toml
, we need that) - be familiar with
Rust
(because it's developed forRust
)
As a reference, my versions are:
cargo
: cargo 1.35.0-nightly (95b45eca1 2019-03-06)rustc
: rustc 1.35.0-nightly (e68bf8ae1 2019-03-11)Linux kernal
: 4.15.0-47-genericUbuntu
: 16.04
usage
install commander-rust
Two ways supported: from Github
or crates.io
.
The difference between them is that Github
is latest but unstable and crates.io
is stable but might not be latest.
install from Github
[]
= "https://github.com/MSDimos/commander_rust"
= "master"
install from crates.io
[]
= "1.1.3" # or other version you want to install
using it
We offer a simple but complete example, you can learn all through it. Yes, That's all. Very easy!
// this is required! Beacuse we used `run!()`, it's a proc_macro
// Only five items you will use
use ;
// what's option? what's command?
// See `commander.js` and document of `commander-rust` for more!
// Note, types of parameters are not fixed, any type implemented `From<Raw>` is valid!
// So you can even use `rmdir(dir: i32, other_dirs: Vec<i32>, cli: Cli)` here.
// And `Cli` is not required! So you can miss it.
// See document of `commander-rust` for more details.
// options here are public, options above `#[command]` are private
try it
try to input [pkg-name] --help
.
version & description & cli-name?
version
, description
, cli-name
of application are from Cargo.toml
.
For instance:
# part of Cargo.toml
[]
= "example-test"
= "0.1.0"
= "Using for test"
error
I can't ensure that it will work perfectly in all cases. My abilities are very limited, testing is not my skill and be sorry about that. I'm learning it. So if you find any BUG, please tell me. Thanks.
examples
Two examples here. One is cargo-bp and the other one is hash.
homepage
Under development. See ./homepage
rules
There are several rules you should follow.
- All
#[options]
should defined above#[command]
and#[entry]
- DO NOT define options duplicate!!! As a concession, You can define the same option on different command and entry.
- Private options are visible to specific sub-commands. Public options are visible to all sub-commands.
- At least one sub-command!
warn
The crate is developed using Ubuntu 16.04
, we can't assume that all platforms will work well.
If you find that it can't work well in other platforms, please tell me.
contribute
Any useful contribute are welcome. You can send pull request to me.
License
GPL-3.0. Because open source is future.