summaryrefslogtreecommitdiffstats
path: root/vendor/xflags-macros/tests/it/repeated_pos.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--vendor/xflags-macros/tests/it/repeated_pos.rs64
1 files changed, 40 insertions, 24 deletions
diff --git a/vendor/xflags-macros/tests/it/repeated_pos.rs b/vendor/xflags-macros/tests/it/repeated_pos.rs
index 334af371d..b11b90717 100644
--- a/vendor/xflags-macros/tests/it/repeated_pos.rs
+++ b/vendor/xflags-macros/tests/it/repeated_pos.rs
@@ -10,7 +10,10 @@ pub struct RepeatedPos {
}
impl RepeatedPos {
- pub const HELP: &'static str = Self::HELP_;
+ #[allow(dead_code)]
+ pub fn from_env_or_exit() -> Self {
+ Self::from_env_or_exit_()
+ }
#[allow(dead_code)]
pub fn from_env() -> xflags::Result<Self> {
@@ -24,6 +27,9 @@ impl RepeatedPos {
}
impl RepeatedPos {
+ fn from_env_or_exit_() -> Self {
+ Self::from_env_().unwrap_or_else(|err| err.exit())
+ }
fn from_env_() -> xflags::Result<Self> {
let mut p = xflags::rt::Parser::new_from_env();
Self::parse_(&mut p)
@@ -36,41 +42,47 @@ impl RepeatedPos {
impl RepeatedPos {
fn parse_(p_: &mut xflags::rt::Parser) -> xflags::Result<Self> {
+ #![allow(non_snake_case)]
let mut a = (false, Vec::new());
let mut b = (false, Vec::new());
let mut c = (false, Vec::new());
let mut rest = (false, Vec::new());
+ let mut state_ = 0u8;
while let Some(arg_) = p_.pop_flag() {
match arg_ {
- Ok(flag_) => match flag_.as_str() {
+ Ok(flag_) => match (state_, flag_.as_str()) {
+ (0, "--help" | "-h") => return Err(p_.help(Self::HELP_)),
_ => return Err(p_.unexpected_flag(&flag_)),
},
- Err(arg_) => {
- if let (done_ @ false, buf_) = &mut a {
- buf_.push(arg_.into());
- *done_ = true;
- continue;
- }
- if let (done_ @ false, buf_) = &mut b {
- buf_.push(p_.value_from_str::<u32>("b", arg_)?);
- *done_ = true;
- continue;
+ Err(arg_) => match (state_, arg_.to_str().unwrap_or("")) {
+ (0, _) => {
+ if let (done_ @ false, buf_) = &mut a {
+ buf_.push(arg_.into());
+ *done_ = true;
+ continue;
+ }
+ if let (done_ @ false, buf_) = &mut b {
+ buf_.push(p_.value_from_str::<u32>("b", arg_)?);
+ *done_ = true;
+ continue;
+ }
+ if let (done_ @ false, buf_) = &mut c {
+ buf_.push(arg_.into());
+ *done_ = true;
+ continue;
+ }
+ if let (false, buf_) = &mut rest {
+ buf_.push(arg_.into());
+ continue;
+ }
+ return Err(p_.unexpected_arg(arg_));
}
- if let (done_ @ false, buf_) = &mut c {
- buf_.push(arg_.into());
- *done_ = true;
- continue;
- }
- if let (false, buf_) = &mut rest {
- buf_.push(arg_.into());
- continue;
- }
- return Err(p_.unexpected_arg(arg_));
- }
+ _ => return Err(p_.unexpected_arg(arg_)),
+ },
}
}
- Ok(Self {
+ Ok(RepeatedPos {
a: p_.required("a", a.1)?,
b: p_.optional("b", b.1)?,
c: p_.optional("c", c.1)?,
@@ -90,5 +102,9 @@ ARGS:
[c]
<rest>...
+
+OPTIONS:
+ -h, --help
+ Prints help information.
";
}