This crate provides attribute macros for command-line argument parsing.
Usage
Just by adding an attribute #[cmd] to a function, the function is converted to a command line program.
$ cargo run
error: The following required arguments were not provided:
<HOST>
<PORT>
USAGE:
argopt-test <HOST> <PORT>
For more information try --help
$ cargo run -- --help
argopt-test
USAGE:
argopt-test <HOST> <PORT>
ARGS:
<HOST>
<PORT>
OPTIONS:
-h, --help Print help information
You can customize the behavior of arguments by annotating them with #[opt(...)] attributes.
And you can add help messages by adding doccomments.
/// Sample program
You can also use the #[opt(...)] attribute to customize the behavior of an application.
/// Sample program
$ cargo run -- --help
argopt-test 0.1.0
Sample program
USAGE:
argopt-test [OPTIONS] --host <HOST>
OPTIONS:
-h, --host <HOST> Host name
--help Print help information
-p, --port <PORT> Port number [default: 80]
-V, --version Print version information
The available options are the same as those of clap::Parser.
Subcommands
You can create sub commands by adding the attribute #[subcmd] to functions.
use ;
use PathBuf;
Easy Verbosity Level Handling
There is a feature that allows you to interact with the log crate and handle the verbosity level automatically.
use cmd;
use *;
$ cargo run
This is error
$ cargo run -- -v
This is error
This is warn
$ cargo run -- -vv
This is error
This is warn
This is info
$ cargo run -- -vvv
This is error
This is warn
This is info
This is debug
$ cargo run -- -vvvv
This is error
This is warn
This is info
This is debug
This is trace
You can also use verbose option to subcommand application.
...