diff options
Diffstat (limited to 'vendor/xflags-macros/tests/it/subcommands.rs')
-rw-r--r-- | vendor/xflags-macros/tests/it/subcommands.rs | 174 |
1 files changed, 62 insertions, 112 deletions
diff --git a/vendor/xflags-macros/tests/it/subcommands.rs b/vendor/xflags-macros/tests/it/subcommands.rs index 7941a395d..4d0a64923 100644 --- a/vendor/xflags-macros/tests/it/subcommands.rs +++ b/vendor/xflags-macros/tests/it/subcommands.rs @@ -41,7 +41,10 @@ pub struct AnalysisStats { } impl RustAnalyzer { - 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> { @@ -55,6 +58,9 @@ impl RustAnalyzer { } impl RustAnalyzer { + 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) @@ -67,130 +73,71 @@ impl RustAnalyzer { impl RustAnalyzer { fn parse_(p_: &mut xflags::rt::Parser) -> xflags::Result<Self> { + #![allow(non_snake_case)] let mut verbose = Vec::new(); + let mut server__dir = Vec::new(); + let mut server__launch__log = Vec::new(); + let mut analysis_stats__parallel = Vec::new(); + let mut analysis_stats__path = (false, 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() { - "--verbose" | "-v" => verbose.push(()), + Ok(flag_) => match (state_, flag_.as_str()) { + (0 | 1 | 2 | 3 | 4, "--verbose" | "-v") => verbose.push(()), + (0 | 1 | 2 | 3 | 4, "--help" | "-h") => return Err(p_.help(Self::HELP_)), + (1 | 2 | 3, "--dir") => server__dir.push(p_.next_value(&flag_)?.into()), + (1, _) => { + p_.push_back(Ok(flag_)); + state_ = 2; + } + (2, "--log") => server__launch__log.push(()), + (4, "--parallel") => analysis_stats__parallel.push(()), _ => return Err(p_.unexpected_flag(&flag_)), }, - Err(arg_) => { - match arg_.to_str().unwrap_or("") { - "server" => { - sub_ = Some(RustAnalyzerCmd::Server(Server::parse_(p_)?)); - break; - } - "analysis-stats" => { - sub_ = Some(RustAnalyzerCmd::AnalysisStats(AnalysisStats::parse_(p_)?)); - break; - } - _ => (), + Err(arg_) => match (state_, arg_.to_str().unwrap_or("")) { + (0, "server") => state_ = 1, + (0, "analysis-stats") => state_ = 4, + (0, _) => { + return Err(p_.unexpected_arg(arg_)); } - return Err(p_.unexpected_arg(arg_)); - } - } - } - Ok(Self { verbose: verbose.len() as u32, subcommand: p_.subcommand(sub_)? }) - } -} - -impl Server { - fn parse_(p_: &mut xflags::rt::Parser) -> xflags::Result<Self> { - let mut dir = Vec::new(); - - let mut sub_ = None; - while let Some(arg_) = p_.pop_flag() { - match arg_ { - Ok(flag_) => match flag_.as_str() { - "--dir" => dir.push(p_.next_value(&flag_)?.into()), - _ => { - p_.push_back(Ok(flag_)); - break; + (1, "watch") => state_ = 3, + (1, _) => { + p_.push_back(Err(arg_)); + state_ = 2; } - }, - Err(arg_) => { - match arg_.to_str().unwrap_or("") { - "watch" => { - sub_ = Some(ServerCmd::Watch(Watch::parse_(p_)?)); - break; + (4, _) => { + if let (done_ @ false, buf_) = &mut analysis_stats__path { + buf_.push(arg_.into()); + *done_ = true; + continue; } - _ => (), + return Err(p_.unexpected_arg(arg_)); } - p_.push_back(Err(arg_)); - break; - } - } - } - if sub_.is_none() { - sub_ = Some(ServerCmd::Launch(Launch::parse_(p_)?)); - } - Ok(Self { dir: p_.optional("--dir", dir)?, subcommand: p_.subcommand(sub_)? }) - } -} - -impl Launch { - fn parse_(p_: &mut xflags::rt::Parser) -> xflags::Result<Self> { - let mut log = Vec::new(); - - while let Some(arg_) = p_.pop_flag() { - match arg_ { - Ok(flag_) => match flag_.as_str() { - "--log" => log.push(()), - _ => return Err(p_.unexpected_flag(&flag_)), - }, - Err(arg_) => { - return Err(p_.unexpected_arg(arg_)); - } - } - } - Ok(Self { log: p_.optional("--log", log)?.is_some() }) - } -} - -impl Watch { - fn parse_(p_: &mut xflags::rt::Parser) -> xflags::Result<Self> { - while let Some(arg_) = p_.pop_flag() { - match arg_ { - Ok(flag_) => match flag_.as_str() { - _ => return Err(p_.unexpected_flag(&flag_)), + _ => return Err(p_.unexpected_arg(arg_)), }, - Err(arg_) => { - return Err(p_.unexpected_arg(arg_)); - } } } - Ok(Self {}) - } -} - -impl AnalysisStats { - fn parse_(p_: &mut xflags::rt::Parser) -> xflags::Result<Self> { - let mut parallel = Vec::new(); - - let mut path = (false, Vec::new()); - - while let Some(arg_) = p_.pop_flag() { - match arg_ { - Ok(flag_) => match flag_.as_str() { - "--parallel" => parallel.push(()), - _ => return Err(p_.unexpected_flag(&flag_)), - }, - Err(arg_) => { - if let (done_ @ false, buf_) = &mut path { - buf_.push(arg_.into()); - *done_ = true; - continue; - } - return Err(p_.unexpected_arg(arg_)); - } - } - } - Ok(Self { - path: p_.required("path", path.1)?, - - parallel: p_.optional("--parallel", parallel)?.is_some(), + state_ = if state_ == 1 { 2 } else { state_ }; + Ok(RustAnalyzer { + verbose: verbose.len() as u32, + subcommand: match state_ { + 2 | 3 => RustAnalyzerCmd::Server(Server { + dir: p_.optional("--dir", server__dir)?, + subcommand: match state_ { + 2 => ServerCmd::Launch(Launch { + log: p_.optional("--log", server__launch__log)?.is_some(), + }), + 3 => ServerCmd::Watch(Watch {}), + _ => return Err(p_.subcommand_required()), + }, + }), + 4 => RustAnalyzerCmd::AnalysisStats(AnalysisStats { + parallel: p_.optional("--parallel", analysis_stats__parallel)?.is_some(), + path: p_.required("path", analysis_stats__path.1)?, + }), + _ => return Err(p_.subcommand_required()), + }, }) } } @@ -201,6 +148,9 @@ rust-analyzer OPTIONS: -v, --verbose + -h, --help + Prints help information. + SUBCOMMANDS: rust-analyzer server |