summaryrefslogtreecommitdiffstats
path: root/vendor/xflags-macros/tests/it/help.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:11:38 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:12:43 +0000
commitcf94bdc0742c13e2a0cac864c478b8626b266e1b (patch)
tree044670aa50cc5e2b4229aa0b6b3df6676730c0a6 /vendor/xflags-macros/tests/it/help.rs
parentAdding debian version 1.65.0+dfsg1-2. (diff)
downloadrustc-cf94bdc0742c13e2a0cac864c478b8626b266e1b.tar.xz
rustc-cf94bdc0742c13e2a0cac864c478b8626b266e1b.zip
Merging upstream version 1.66.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/xflags-macros/tests/it/help.rs')
-rw-r--r--vendor/xflags-macros/tests/it/help.rs84
1 files changed, 38 insertions, 46 deletions
diff --git a/vendor/xflags-macros/tests/it/help.rs b/vendor/xflags-macros/tests/it/help.rs
index 36a966485..f17062988 100644
--- a/vendor/xflags-macros/tests/it/help.rs
+++ b/vendor/xflags-macros/tests/it/help.rs
@@ -21,7 +21,10 @@ pub struct Sub {
}
impl Helpful {
- 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> {
@@ -35,6 +38,9 @@ impl Helpful {
}
impl Helpful {
+ 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)
@@ -47,68 +53,51 @@ impl Helpful {
impl Helpful {
fn parse_(p_: &mut xflags::rt::Parser) -> xflags::Result<Self> {
+ #![allow(non_snake_case)]
let mut switch = Vec::new();
-
let mut src = (false, Vec::new());
let mut extra = (false, Vec::new());
+ let mut sub__flag = Vec::new();
- let mut sub_ = None;
+ let mut state_ = 0u8;
while let Some(arg_) = p_.pop_flag() {
match arg_ {
- Ok(flag_) => match flag_.as_str() {
- "--switch" | "-s" => switch.push(()),
+ Ok(flag_) => match (state_, flag_.as_str()) {
+ (0 | 1, "--switch" | "-s") => switch.push(()),
+ (0 | 1, "--help" | "-h") => return Err(p_.help(Self::HELP_)),
+ (1, "--flag" | "-f") => sub__flag.push(()),
_ => return Err(p_.unexpected_flag(&flag_)),
},
- Err(arg_) => {
- match arg_.to_str().unwrap_or("") {
- "sub" => {
- sub_ = Some(HelpfulCmd::Sub(Sub::parse_(p_)?));
- break;
+ Err(arg_) => match (state_, arg_.to_str().unwrap_or("")) {
+ (0, "sub") => state_ = 1,
+ (0, _) => {
+ if let (done_ @ false, buf_) = &mut src {
+ buf_.push(arg_.into());
+ *done_ = true;
+ continue;
}
- _ => (),
- }
- if let (done_ @ false, buf_) = &mut src {
- buf_.push(arg_.into());
- *done_ = true;
- continue;
- }
- if let (done_ @ false, buf_) = &mut extra {
- buf_.push(p_.value_from_str::<String>("extra", arg_)?);
- *done_ = true;
- continue;
+ if let (done_ @ false, buf_) = &mut extra {
+ buf_.push(p_.value_from_str::<String>("extra", arg_)?);
+ *done_ = true;
+ continue;
+ }
+ return Err(p_.unexpected_arg(arg_));
}
- return Err(p_.unexpected_arg(arg_));
- }
+ _ => return Err(p_.unexpected_arg(arg_)),
+ },
}
}
- Ok(Self {
+ Ok(Helpful {
+ switch: p_.required("--switch", switch)?,
src: p_.optional("src", src.1)?,
extra: p_.optional("extra", extra.1)?,
-
- switch: p_.required("--switch", switch)?,
- subcommand: p_.subcommand(sub_)?,
+ subcommand: match state_ {
+ 1 => HelpfulCmd::Sub(Sub { flag: p_.optional("--flag", sub__flag)?.is_some() }),
+ _ => return Err(p_.subcommand_required()),
+ },
})
}
}
-
-impl Sub {
- fn parse_(p_: &mut xflags::rt::Parser) -> xflags::Result<Self> {
- let mut flag = Vec::new();
-
- while let Some(arg_) = p_.pop_flag() {
- match arg_ {
- Ok(flag_) => match flag_.as_str() {
- "--flag" | "-f" => flag.push(()),
- _ => return Err(p_.unexpected_flag(&flag_)),
- },
- Err(arg_) => {
- return Err(p_.unexpected_arg(arg_));
- }
- }
- }
- Ok(Self { flag: p_.optional("--flag", flag)?.is_some() })
- }
-}
impl Helpful {
const HELP_: &'static str = "\
helpful
@@ -131,6 +120,9 @@ OPTIONS:
-s, --switch
And a switch.
+ -h, --help
+ Prints help information.
+
SUBCOMMANDS:
helpful sub