rustc/vendor/xflags-macros-0.3.2/tests/it/empty.rs
2024-06-24 14:48:22 +02:00

66 lines
1.6 KiB
Rust

#[allow(unused)]
use std::{ffi::OsString, path::PathBuf};
#[derive(Debug)]
pub struct Empty;
impl Empty {
#[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> {
Self::from_env_()
}
#[allow(dead_code)]
pub fn from_vec(args: Vec<std::ffi::OsString>) -> xflags::Result<Self> {
Self::from_vec_(args)
}
}
impl Empty {
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)
}
fn from_vec_(args: Vec<std::ffi::OsString>) -> xflags::Result<Self> {
let mut p = xflags::rt::Parser::new(args);
Self::parse_(&mut p)
}
}
impl Empty {
fn parse_(p_: &mut xflags::rt::Parser) -> xflags::Result<Self> {
#![allow(non_snake_case, unused_mut)]
let mut state_ = 0u8;
while let Some(arg_) = p_.pop_flag() {
match arg_ {
Ok(flag_) => match (state_, flag_.as_str()) {
(0, "--help" | "-h") => return Err(p_.help(Self::HELP_)),
_ => return Err(p_.unexpected_flag(&flag_)),
},
Err(arg_) => match (state_, arg_.to_str().unwrap_or("")) {
_ => return Err(p_.unexpected_arg(arg_)),
},
}
}
Ok(Empty {})
}
}
impl Empty {
const HELP_: &'static str = "\
empty
OPTIONS:
-h, --help
Prints help information.
";
}