Arg::validator Arg::allow_invalid_utf8 等 API,引入了更加开放和灵活的 API,例如:/*
#[non_exhaustive]
pub enum ArgAction {
Set,
Append,
StoreValue,
IncOccurrence,
SetTrue,
SetFalse,
Count,
Help,
Version,
}
*/let cmd = Command::new("mycmd")
.arg(
Arg::new("quiet")
.long("quiet")
.action(clap::builder::ArgAction::SetTrue)
)
.arg(
Arg::new("verbose")
.long("verbose")
.action(clap::builder::ArgAction::Count)
);let matches = cmd.try_get_matches_from(
["mycmd", "--quiet", "--quiet", "--verbose", "--verbose", "--verbose"]
).unwrap();assert_eq!(
*matches.get_one::<bool>("quiet").expect("defaulted by clap"), Some(true)
);assert_eq!(
*matches.get_one::<u8>("verbose").expect("defaulted by clap"), Some(3)
);


github地址:https://github.com/p4ddy1/gbemulator
原文作者:Rust语言中文社区;如有侵权,请联系管理员删除。