From f6e674d190e4225bd4c97942e2a4d708cad477a9 Mon Sep 17 00:00:00 2001 From: Avril Date: Mon, 22 Feb 2021 21:06:22 +0000 Subject: [PATCH] ported arg parsers to parse_next --- src/arg/mod.rs | 4 ++-- src/arg/parsing.rs | 60 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 51 insertions(+), 13 deletions(-) diff --git a/src/arg/mod.rs b/src/arg/mod.rs index 9ee3235..abdb587 100644 --- a/src/arg/mod.rs +++ b/src/arg/mod.rs @@ -36,7 +36,7 @@ const OPTIONS_NORMAL: &'static [&'static str] = &[ #[cfg(feature="inspect")] "--save Dump the collected data to this file for further inspection.", #[cfg(feature="inspect")] "-D Dump the collected data to `stdout` (see `--save`.)", #[cfg(feature="inspect")] "--save-raw Dump the collected data to this file uncompressed. (see `--save`.)", - #[cfg(feature="inspect")] "-Dr Dump the collected data to standard output uncompressed. (see `--save-raw`.)", + #[cfg(feature="inspect")] "-R Dump the collected data to standard output uncompressed. (see `--save-raw`.)", "- Stop parsing arguments, treat all the rest as paths.", ]; @@ -153,7 +153,7 @@ fn parse>(args: I) -> eyre::Result #[cfg(feature="inspect")] "-D" => { cfg.serialise_output = Some(config::OutputSerialisationMode::Stdout); }, - #[cfg(feature="inspect")] "-Dr" => { + #[cfg(feature="inspect")] "-R" => { cfg.serialise_output = Some(config::OutputSerialisationMode::RawStdout); }, #[cfg(feature="inspect")] "--save" => { diff --git a/src/arg/parsing.rs b/src/arg/parsing.rs index bc64572..5abff2c 100644 --- a/src/arg/parsing.rs +++ b/src/arg/parsing.rs @@ -223,11 +223,44 @@ pub type Output = HashSet; "If this was intended as a path instead of an option, use option `-` before it." } -fn parse_single(args: &mut I, output: &mut Output, this: char) -> eyre::Result +fn save_output(output: &mut Output, item: Argument) -> eyre::Result<()> +{ + if let Some(mx) = output.iter().filter(|arg| item.is_mx_with(arg)).next() { + return Err(eyre!("Arguments are mutually exclusive")) + .with_section(|| item.header("Trying to add")) + .with_section(|| mx.to_string().header("Which is mutually exclusive with")); + } + + output.insert(item); //TODO: Warn when adding duplicate? + + Ok(()) +} + +fn parse_single(_args: &mut I, output: &mut Output, this: char) -> eyre::Result where I: Iterator - { - //TODO: Parse single letter args + let item = match this + { + 'r' => Argument::UnlimitRecurse, + + #[cfg(feature="inspect")] 'D' => Argument::SaveStdout, + #[cfg(feature="inspect")] 'R' => Argument::SaveRawStdout, + + 'v' => Argument::LogVerbose, + 'q' => Argument::LogQuiet, + 'Q' => Argument::LogSilent, + + 'm' => Argument::LimitConcMaxProc, + 'M' => Argument::UnlimitConc, + + unknown => { + return Err(eyre!("Unknown short argument {:?}", unknown)) + .with_suggestion(suggestion_intended_arg.clone()); + }, + }; + + save_output(output, item)?; + Ok(Continue::Yes) } @@ -256,7 +289,18 @@ where I: Iterator "-" => { return Ok(Continue::No); }, - //TODO: move rest of long args from `mod` to here + #[cfg(feature="inspect")] "--save" => { + let file = args.next().ok_or(eyre!("`--save` expects a parameter")) + .with_suggestion(suggestion_intended_arg.clone())?; + + Argument::Save(file) + }, + #[cfg(feature="inspect")] "--save-raw" => { + let file = args.next().ok_or(eyre!("`--save` expects a parameter")) + .with_suggestion(suggestion_intended_arg.clone())?; + + Argument::SaveRaw(file) + }, single if single.starts_with("-") => { for ch in single.chars().skip(1) { match parse_single(args, output, ch)? { @@ -274,13 +318,7 @@ where I: Iterator } }; - if let Some(mx) = output.iter().filter(|arg| item.is_mx_with(arg)).next() { - return Err(eyre!("Arguments are mutually exclusive")) - .with_section(|| item.header("Trying to add")) - .with_section(|| mx.to_string().header("Which is mutually exclusive with")); - } - - output.insert(item); //TODO: Warn when adding duplicate? + save_output(output, item)?; Ok(keep_reading) }