From dfbf78622b0869f070d062b3edd40c4a97ce7dfd Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 16 Feb 2019 01:48:59 +0100 Subject: introduce CommaSeparatedList This gives a common interface for command line flags which take multiple values, possibly with negation. This might come in useful if we add filtering by boss, e.g. "--boss !deimos" to ignore all deimos logs. --- src/main.rs | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index a77a952..13d0a76 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,6 +30,9 @@ mod output; mod filters; +mod csl; +use csl::CommaSeparatedList; + macro_rules! unwrap { ($p:pat = $e:expr => { $r:expr} ) => { if let $p = $e { @@ -75,12 +78,12 @@ pub struct Opt { path: PathBuf, /// The fields which should be searched. - #[structopt(short = "f", long = "fields", default_value = "all")] - field: SearchField, + #[structopt(short = "f", long = "fields", default_value = "*")] + field: CommaSeparatedList, /// Only display fights with the given outcome. - #[structopt(short = "o", long = "outcome")] - outcome: Option, + #[structopt(short = "o", long = "outcome", default_value = "*")] + outcome: CommaSeparatedList, /// Disable colored output. #[structopt(long = "no-color")] @@ -112,39 +115,22 @@ pub struct Opt { } /// A flag indicating which fields should be searched. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] enum SearchField { - /// Search all fields. - All, /// Only search the account name. Account, /// Only search the character name. Character, } -impl SearchField { - /// True if the state says that the account name should be searched. - #[inline] - fn search_account(self) -> bool { - self == SearchField::All || self == SearchField::Account - } - - /// True if the state says that the character name should be searched. - #[inline] - fn search_character(self) -> bool { - self == SearchField::All || self == SearchField::Character - } -} - impl FromStr for SearchField { type Err = &'static str; fn from_str(s: &str) -> Result { match s { - "all" => Ok(SearchField::All), "account" => Ok(SearchField::Account), "character" => Ok(SearchField::Character), - _ => Err("Must be all, account or character"), + _ => Err("Must be account or character"), } } } @@ -178,7 +164,7 @@ pub struct Player { } /// Outcome of the fight. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum FightOutcome { Success, Wipe, -- cgit v1.2.3