From cf94bdc0742c13e2a0cac864c478b8626b266e1b Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:11:38 +0200 Subject: Merging upstream version 1.66.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/xflags-macros/tests/data/help.rs | 26 ++++ vendor/xflags-macros/tests/data/repeated_pos.rs | 8 + vendor/xflags-macros/tests/data/smoke.rs | 14 ++ vendor/xflags-macros/tests/data/subcommands.rs | 19 +++ vendor/xflags-macros/tests/it/help.rs | 84 +++++------ vendor/xflags-macros/tests/it/main.rs | 36 ++++- vendor/xflags-macros/tests/it/repeated_pos.rs | 64 +++++--- vendor/xflags-macros/tests/it/smoke.rs | 61 +++++--- vendor/xflags-macros/tests/it/src/help.rs | 25 ---- vendor/xflags-macros/tests/it/src/repeated_pos.rs | 9 -- vendor/xflags-macros/tests/it/src/smoke.rs | 15 -- vendor/xflags-macros/tests/it/src/subcommands.rs | 20 --- vendor/xflags-macros/tests/it/subcommands.rs | 174 ++++++++-------------- 13 files changed, 279 insertions(+), 276 deletions(-) create mode 100644 vendor/xflags-macros/tests/data/help.rs create mode 100644 vendor/xflags-macros/tests/data/repeated_pos.rs create mode 100644 vendor/xflags-macros/tests/data/smoke.rs create mode 100644 vendor/xflags-macros/tests/data/subcommands.rs delete mode 100644 vendor/xflags-macros/tests/it/src/help.rs delete mode 100644 vendor/xflags-macros/tests/it/src/repeated_pos.rs delete mode 100644 vendor/xflags-macros/tests/it/src/smoke.rs delete mode 100644 vendor/xflags-macros/tests/it/src/subcommands.rs (limited to 'vendor/xflags-macros/tests') diff --git a/vendor/xflags-macros/tests/data/help.rs b/vendor/xflags-macros/tests/data/help.rs new file mode 100644 index 000000000..f252e34fa --- /dev/null +++ b/vendor/xflags-macros/tests/data/help.rs @@ -0,0 +1,26 @@ +xflags! { + /// Does stuff + /// + /// Helpful stuff. + cmd helpful { + /// With an arg. + optional src: PathBuf + + /// Another arg. + /// + /// This time, we provide some extra info about the + /// arg. Maybe some caveats, or what kinds of + /// values are accepted. + optional extra: String + + /// And a switch. + required -s, --switch + + /// And even a subcommand! + cmd sub { + /// With an optional flag. This has a really long + /// description which spans multiple lines. + optional -f, --flag + } + } +} diff --git a/vendor/xflags-macros/tests/data/repeated_pos.rs b/vendor/xflags-macros/tests/data/repeated_pos.rs new file mode 100644 index 000000000..be7c552e0 --- /dev/null +++ b/vendor/xflags-macros/tests/data/repeated_pos.rs @@ -0,0 +1,8 @@ +xflags! { + cmd RepeatedPos { + required a: PathBuf + optional b: u32 + optional c: OsString + repeated rest: OsString + } +} diff --git a/vendor/xflags-macros/tests/data/smoke.rs b/vendor/xflags-macros/tests/data/smoke.rs new file mode 100644 index 000000000..55da2d3ef --- /dev/null +++ b/vendor/xflags-macros/tests/data/smoke.rs @@ -0,0 +1,14 @@ +xflags! { + /// LSP server for rust. + cmd rust-analyzer { + required workspace: PathBuf + /// Number of concurrent jobs. + optional jobs: u32 + /// Path to log file. By default, logs go to stderr. + optional --log-file path: PathBuf + repeated -v, --verbose + required -n, --number n: u32 + repeated --data value: OsString + optional --emoji + } +} diff --git a/vendor/xflags-macros/tests/data/subcommands.rs b/vendor/xflags-macros/tests/data/subcommands.rs new file mode 100644 index 000000000..45fab8232 --- /dev/null +++ b/vendor/xflags-macros/tests/data/subcommands.rs @@ -0,0 +1,19 @@ +xflags! { + cmd rust-analyzer { + repeated -v, --verbose + + cmd server { + optional --dir path:PathBuf + default cmd launch { + optional --log + } + cmd watch { + } + } + + cmd analysis-stats { + required path: PathBuf + optional --parallel + } + } +} 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 { @@ -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 { 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 { + #![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::("extra", arg_)?); - *done_ = true; - continue; + if let (done_ @ false, buf_) = &mut extra { + buf_.push(p_.value_from_str::("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 { - 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 diff --git a/vendor/xflags-macros/tests/it/main.rs b/vendor/xflags-macros/tests/it/main.rs index 1ce058814..7d77bda36 100644 --- a/vendor/xflags-macros/tests/it/main.rs +++ b/vendor/xflags-macros/tests/it/main.rs @@ -67,9 +67,10 @@ fn smoke() { "-n 92 --werbose", expect![[r#"unexpected flag: `--werbose`"#]], ); - check(smoke::RustAnalyzer::from_vec, "", expect![[r#"flag is required: `workspace`"#]]); + check(smoke::RustAnalyzer::from_vec, "", expect!["flag is required: `--number`"]); check(smoke::RustAnalyzer::from_vec, ".", expect![[r#"flag is required: `--number`"#]]); check(smoke::RustAnalyzer::from_vec, "-n", expect![[r#"expected a value for `-n`"#]]); + check(smoke::RustAnalyzer::from_vec, "-n 92", expect!["flag is required: `workspace`"]); check( smoke::RustAnalyzer::from_vec, "-n lol", @@ -196,3 +197,36 @@ fn subcommands() { check(subcommands::RustAnalyzer::from_vec, "", expect![[r#"subcommand is required"#]]); } + +#[test] +fn subcommand_flag_inheritance() { + check( + subcommands::RustAnalyzer::from_vec, + "server watch --verbose --dir .", + expect![[r#" + RustAnalyzer { + verbose: 1, + subcommand: Server( + Server { + dir: Some( + ".", + ), + subcommand: Watch( + Watch, + ), + }, + ), + } + "#]], + ); + check( + subcommands::RustAnalyzer::from_vec, + "analysis-stats --verbose --dir .", + expect!["unexpected flag: `--dir`"], + ); + check( + subcommands::RustAnalyzer::from_vec, + "--dir . server", + expect!["unexpected flag: `--dir`"], + ); +} 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 { @@ -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 { 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 { + #![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::("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::("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] ... + +OPTIONS: + -h, --help + Prints help information. "; } diff --git a/vendor/xflags-macros/tests/it/smoke.rs b/vendor/xflags-macros/tests/it/smoke.rs index e22c4f1f6..f2ebbb712 100644 --- a/vendor/xflags-macros/tests/it/smoke.rs +++ b/vendor/xflags-macros/tests/it/smoke.rs @@ -14,7 +14,10 @@ pub struct RustAnalyzer { } 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 { @@ -28,6 +31,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 { let mut p = xflags::rt::Parser::new_from_env(); Self::parse_(&mut p) @@ -40,49 +46,53 @@ impl RustAnalyzer { impl RustAnalyzer { fn parse_(p_: &mut xflags::rt::Parser) -> xflags::Result { + #![allow(non_snake_case)] let mut log_file = Vec::new(); let mut verbose = Vec::new(); let mut number = Vec::new(); let mut data = Vec::new(); let mut emoji = Vec::new(); - let mut workspace = (false, Vec::new()); let mut jobs = (false, Vec::new()); + let mut state_ = 0u8; while let Some(arg_) = p_.pop_flag() { match arg_ { - Ok(flag_) => match flag_.as_str() { - "--log-file" => log_file.push(p_.next_value(&flag_)?.into()), - "--verbose" | "-v" => verbose.push(()), - "--number" | "-n" => number.push(p_.next_value_from_str::(&flag_)?), - "--data" => data.push(p_.next_value(&flag_)?.into()), - "--emoji" => emoji.push(()), + Ok(flag_) => match (state_, flag_.as_str()) { + (0, "--log-file") => log_file.push(p_.next_value(&flag_)?.into()), + (0, "--verbose" | "-v") => verbose.push(()), + (0, "--number" | "-n") => number.push(p_.next_value_from_str::(&flag_)?), + (0, "--data") => data.push(p_.next_value(&flag_)?.into()), + (0, "--emoji") => emoji.push(()), + (0, "--help" | "-h") => return Err(p_.help(Self::HELP_)), _ => return Err(p_.unexpected_flag(&flag_)), }, - Err(arg_) => { - if let (done_ @ false, buf_) = &mut workspace { - buf_.push(arg_.into()); - *done_ = true; - continue; - } - if let (done_ @ false, buf_) = &mut jobs { - buf_.push(p_.value_from_str::("jobs", arg_)?); - *done_ = true; - continue; + Err(arg_) => match (state_, arg_.to_str().unwrap_or("")) { + (0, _) => { + if let (done_ @ false, buf_) = &mut workspace { + buf_.push(arg_.into()); + *done_ = true; + continue; + } + if let (done_ @ false, buf_) = &mut jobs { + buf_.push(p_.value_from_str::("jobs", arg_)?); + *done_ = true; + continue; + } + return Err(p_.unexpected_arg(arg_)); } - return Err(p_.unexpected_arg(arg_)); - } + _ => return Err(p_.unexpected_arg(arg_)), + }, } } - Ok(Self { - workspace: p_.required("workspace", workspace.1)?, - jobs: p_.optional("jobs", jobs.1)?, - + Ok(RustAnalyzer { log_file: p_.optional("--log-file", log_file)?, verbose: verbose.len() as u32, number: p_.required("--number", number)?, data: data, emoji: p_.optional("--emoji", emoji)?.is_some(), + workspace: p_.required("workspace", workspace.1)?, + jobs: p_.optional("jobs", jobs.1)?, }) } } @@ -108,5 +118,8 @@ OPTIONS: --data --emoji + + -h, --help + Prints help information. "; } diff --git a/vendor/xflags-macros/tests/it/src/help.rs b/vendor/xflags-macros/tests/it/src/help.rs deleted file mode 100644 index d552c1e63..000000000 --- a/vendor/xflags-macros/tests/it/src/help.rs +++ /dev/null @@ -1,25 +0,0 @@ -xflags! { - /// Does stuff - /// - /// Helpful stuff. - cmd helpful - /// With an arg. - optional src: PathBuf - /// Another arg. - /// - /// This time, we provide some extra info about the - /// arg. Maybe some caveats, or what kinds of - /// values are accepted. - optional extra: String - { - /// And a switch. - required -s, --switch - - /// And even a subcommand! - cmd sub { - /// With an optional flag. This has a really long - /// description which spans multiple lines. - optional -f, --flag - } - } -} diff --git a/vendor/xflags-macros/tests/it/src/repeated_pos.rs b/vendor/xflags-macros/tests/it/src/repeated_pos.rs deleted file mode 100644 index 4106c65eb..000000000 --- a/vendor/xflags-macros/tests/it/src/repeated_pos.rs +++ /dev/null @@ -1,9 +0,0 @@ -xflags! { - cmd RepeatedPos - required a: PathBuf - optional b: u32 - optional c: OsString - repeated rest: OsString - { - } -} diff --git a/vendor/xflags-macros/tests/it/src/smoke.rs b/vendor/xflags-macros/tests/it/src/smoke.rs deleted file mode 100644 index ae303779e..000000000 --- a/vendor/xflags-macros/tests/it/src/smoke.rs +++ /dev/null @@ -1,15 +0,0 @@ -xflags! { - /// LSP server for rust. - cmd rust-analyzer - required workspace: PathBuf - /// Number of concurrent jobs. - optional jobs: u32 - { - /// Path to log file. By default, logs go to stderr. - optional --log-file path: PathBuf - repeated -v, --verbose - required -n, --number n: u32 - repeated --data value: OsString - optional --emoji - } -} diff --git a/vendor/xflags-macros/tests/it/src/subcommands.rs b/vendor/xflags-macros/tests/it/src/subcommands.rs deleted file mode 100644 index 70a0a5049..000000000 --- a/vendor/xflags-macros/tests/it/src/subcommands.rs +++ /dev/null @@ -1,20 +0,0 @@ -xflags! { - cmd rust-analyzer { - repeated -v, --verbose - - cmd server { - optional --dir path:PathBuf - default cmd launch { - optional --log - } - cmd watch { - } - } - - cmd analysis-stats - required path: PathBuf - { - optional --parallel - } - } -} 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 { @@ -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 { 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 { + #![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 { - 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 { - 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 { - 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 { - 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 -- cgit v1.2.3