From 994a394631392fcfef7553231b8ec31c0561b0f7 Mon Sep 17 00:00:00 2001 From: Avril Date: Mon, 22 Feb 2021 21:36:55 +0000 Subject: [PATCH] Argument::insert_into_cfg --- src/arg/parsing.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/arg/parsing.rs b/src/arg/parsing.rs index 5abff2c..48c5b4a 100644 --- a/src/arg/parsing.rs +++ b/src/arg/parsing.rs @@ -4,10 +4,13 @@ use std::collections::{HashMap, HashSet}; use std::mem::Discriminant; use std::fmt; +use config::OutputSerialisationMode; + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Argument { ModeChangeHelp, + LimitConcMaxProc, LimitConc(NonZeroUsize), UnlimitConc, @@ -29,6 +32,44 @@ pub enum Argument Input(String), } +impl Argument +{ + /// Insert this `Argument` into config + pub fn insert_into_cfg(self, cfg: &mut Config) + { + use Argument::*; + match self { + LimitConcMaxProc => cfg.max_tasks = config::max_tasks_cpus(), + LimitConc(max) => cfg.max_tasks = Some(max), + UnlimitConc => cfg.max_tasks = None, + + #[cfg(feature="inspect")] Save(output) => cfg.serialise_output = Some(OutputSerialisationMode::File(output.into())), + #[cfg(feature="inspect")] SaveStdout => cfg.serialise_output = Some(OutputSerialisationMode::Stdout), + #[cfg(feature="inspect")] SaveRaw(output) => { + cfg_if! { + if #[cfg(feature="prealloc")] { + cfg.serialise_output = Some(OutputSerialisationMode::PreallocFile(output.into())); + } else { + cfg.serialise_output = Some(OutputSerialisationMode::RawFile(output.into())); + } + } + }, + #[cfg(feature="inspect")] SaveRawStdout => cfg.serialise_output = Some(OutputSerialisationMode::RawStdout), + + LimitRecurse(limit) => cfg.recursive = config::Recursion::Limited(limit), + UnlimitRecurse => cfg.recursive = config::Recursion::Unlimited, + + LogVerbose => cfg.output_level = config::OutputLevel::Verbose, + LogQuiet => cfg.output_level = config::OutputLevel::Quiet, + LogSilent => cfg.output_level = config::OutputLevel::Silent, + + Input(path) => cfg.paths.push(path.into()), + + _ => unreachable!(), + } + } +} + impl fmt::Display for Argument { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result