例如,运行我的应用程序
./app --foo=bar get
效果很好,但是
./app get --foo=bar
产生错误:
error: Found argument '--foo' which wasn't expected, or isn't valid in this context
USAGE:
app --foo <foo> get
代码:
use structopt::*;
#[derive(Debug, StructOpt)]
#[structopt(name = "app")]
struct CliArgs {
#[structopt(long)]
foo: String,
#[structopt(subcommand)]
cmd: Cmd,
}
#[derive(Debug, StructOpt)]
enum Cmd {
Get,
Set,
}
fn main() {
let args = CliArgs::from_args();
println!("{:?}", args);
}
依赖项:
structopt = { version = "0.3", features = [ "paw" ] }
paw = "1.0"