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

limit

If you want to use this crate, please guarantee that you have follow rules below:

As a reference, my versions are:

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

install from crates.io

using it

We offer a simple but complete example, you can learn all through it. Yes, That's all. Very easy!

try it

try to input [pkg-name] --help.

version & description & cli-name?

version, description, cli-name of application are from Cargo.toml.

For instance:

direct

If you don't want to define a sub-command, you can use #[direct]. What's direct? In some situations, for instance, if you want to develop a CLI which could be called like rm ./* -rf. If there is no direct. you can only use sub-command, it looks like rm delete ./* -rf. Come on! delete is redundant, we don't like this! It should be rm -rf ./* instead of rm delete ./* -rf. So, it's time to use #[direct].

Now, if you input [pkg-name] 1 2 3, cli will print hello! 1 2. So it allows you that don't need to define a sub-command anymore in some simple situations. direct is supported by only 1.2.x or higher. direct can work together with sub-command well, you can use them both together.

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 full examples here. One is cargo-bp and the other one is hash. And there is a simple example showing all usage of commander-rust, see ./examples for more information.

homepage

Under development. See ./homepage

rules

There are several rules you should follow.

  1. All #[options] should defined above #[command] and #[entry]
  2. DO NOT define options duplicate!!! As a concession, You can define the same option on different command and entry.
  3. Private options are visible to specific sub-commands. Public options are visible to all sub-commands.

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.