0.2.0 |
|
---|---|
0.1.0 |
|
0.0.3 |
|
0.0.2 |
|
0.0.1 |
|
#192 in #command-line-arguments
每月25次下载
在 kwrap 中使用
10KB
172 行
ace
一个简单的命令行参数解析库
安装
在您的 Cargo.toml
中添加此内容
[dependencies]
ace = "0.2.0"
示例
use ace::App;
fn main() {
let app = App::new()
.config("app", env!("CARGO_PKG_VERSION"))
.cmd("start", "Start now")
.cmd("help", "Display help information")
.cmd("version", "Display version information")
.opt("--config", "Use configuration file")
.opt("--duration", vec!["Set duration of test", "example (1ms, 1s, 1m, 1h, 1d)"])
.opt("--timeout", "Set timeout");
if let Some(cmd) = app.command() {
match cmd.as_str() {
"start" => {
dbg!(app.value("--config"));
}
"help" => {
app.print_help();
}
"version" => {
app.print_version();
}
_ => {
app.print_error_try("help");
}
}
} else {
dbg!(app.args());
}
}
输出
app version 0.2.0
Usage:
app [COMMAND] [OPTION]
Command:
start Start now
help Display help information
version Display version information
Option:
--config Use configuration file
--duration Set duration of test
example (1ms, 1s, 1m, 1h, 1d)
--timeout Set timeout