From 7f2222712e3dab1503e1330ba99879567fa8fb5f Mon Sep 17 00:00:00 2001 From: Alex Snaps Date: Mon, 19 Aug 2024 10:39:34 -0400 Subject: [PATCH 1/3] fix flags --- src/main.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9568110..0eb0689 100644 --- a/src/main.rs +++ b/src/main.rs @@ -96,7 +96,7 @@ fn main() { Err(err) => exit!(1, "Couldn't open config file '{}': {}", cfg_src, err), }; - let location_grouping = matches.contains_id("LOCATIONS"); + let location_grouping = matches.get_flag("LOCATIONS"); let date = if let Some(date) = matches.get_many::("DATE") { let date_string = date.cloned().collect::(); @@ -108,7 +108,8 @@ fn main() { Local::now() }; - let team = if matches.contains_id("ALL") { + let team = if matches.get_flag("ALL") { + println!("We are finding ALL?"); None } else if let Some(team) = matches.get_one::("TEAM") { cfg.teams.get(team) From ce55fc9915992031c9a599f1bf37a626c6ef18aa Mon Sep 17 00:00:00 2001 From: Alex Snaps Date: Tue, 20 Aug 2024 07:11:30 -0400 Subject: [PATCH 2/3] Include team name in header --- README.md | 4 ++-- src/config.rs | 7 +++++-- src/main.rs | 18 ++++++++++-------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 9736b4a..58a0853 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ and other daylight saving changes based off their location. Because I know I can ```shell $ tdate ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━┓ -┃ Team member │ Time ┃ +┃ Team wcgw │ Time ┃ ┠──────────────────────────┼──────────────────┨ ┃ Alex (America/Montreal) │ Mon Aug 15 21:18 ┃ ┃ Jane Doe (Europe/Dublin) │ Tue Aug 16 02:18 ┃ @@ -38,7 +38,7 @@ $ tdate -l Aug 28 3pm ```shell $ tdate 3 weeks 10:30am ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━┓ -┃ Team member │ Time ┃ +┃ Team wcgw │ Time ┃ ┠──────────────────────────┼──────────────────┨ ┃ Alex (America/Montreal) │ Mon Sep 05 10:30 ┃ ┃ Jane Doe (Europe/Dublin) │ Mon Sep 05 15:30 ┃ diff --git a/src/config.rs b/src/config.rs index aa9672e..695b030 100644 --- a/src/config.rs +++ b/src/config.rs @@ -35,9 +35,12 @@ impl Config { self.date_format.as_deref().unwrap_or(DEFAULT_DATE_FMT) } - pub fn default_team(&self) -> Option<&Vec> { + pub fn default_team(&self) -> Option<(&str, &Vec)> { match &self.default_team { - Some(name) => self.teams.get(name), + Some(name) => match self.teams.get(name) { + Some(members) => Some((name, members)), + None => None, + }, None => None, } } diff --git a/src/main.rs b/src/main.rs index 0eb0689..db58e00 100644 --- a/src/main.rs +++ b/src/main.rs @@ -108,24 +108,26 @@ fn main() { Local::now() }; - let team = if matches.get_flag("ALL") { - println!("We are finding ALL?"); - None + let (name, team) = if matches.get_flag("ALL") { + (None, None) } else if let Some(team) = matches.get_one::("TEAM") { - cfg.teams.get(team) + match cfg.teams.get(team) { + None => (Some(team.as_str()), None), + Some(members) => (Some(team.as_str()), Some(members)) + } } else { - cfg.default_team() + cfg.default_team().map_or_else(|| (None, None), |(team, members)| (Some(team), Some(members))) }; - let left_header = if location_grouping { "Location" } else { "Team member" }; + let left_header = if location_grouping { "Location".to_owned() } else { format!("Team {}", name.unwrap_or("member")) }; if let Some(members) = team { let lines = team_to_lines(&cfg, location_grouping, date, members); - print_timezones(left_header, "Time", lines); + print_timezones(left_header.as_str(), "Time", lines); } else { for (team, members) in &cfg.teams { println!("\n => Team {}", team); let lines = team_to_lines(&cfg, location_grouping, date, members); - print_timezones(left_header, "Time", lines); + print_timezones(left_header.as_str(), "Time", lines); } } } From fca3871b9259d3295947f9880efb272e4e90bfd6 Mon Sep 17 00:00:00 2001 From: Alex Snaps Date: Tue, 20 Aug 2024 07:12:16 -0400 Subject: [PATCH 3/3] fmt --- src/config.rs | 5 +---- src/main.rs | 12 +++++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/config.rs b/src/config.rs index 695b030..5c3d003 100644 --- a/src/config.rs +++ b/src/config.rs @@ -37,10 +37,7 @@ impl Config { pub fn default_team(&self) -> Option<(&str, &Vec)> { match &self.default_team { - Some(name) => match self.teams.get(name) { - Some(members) => Some((name, members)), - None => None, - }, + Some(name) => self.teams.get(name).map(|members| (name.as_str(), members)), None => None, } } diff --git a/src/main.rs b/src/main.rs index db58e00..e45c8d7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -113,13 +113,19 @@ fn main() { } else if let Some(team) = matches.get_one::("TEAM") { match cfg.teams.get(team) { None => (Some(team.as_str()), None), - Some(members) => (Some(team.as_str()), Some(members)) + Some(members) => (Some(team.as_str()), Some(members)), } } else { - cfg.default_team().map_or_else(|| (None, None), |(team, members)| (Some(team), Some(members))) + cfg + .default_team() + .map_or_else(|| (None, None), |(team, members)| (Some(team), Some(members))) }; - let left_header = if location_grouping { "Location".to_owned() } else { format!("Team {}", name.unwrap_or("member")) }; + let left_header = if location_grouping { + "Location".to_owned() + } else { + format!("Team {}", name.unwrap_or("member")) + }; if let Some(members) = team { let lines = team_to_lines(&cfg, location_grouping, date, members); print_timezones(left_header.as_str(), "Time", lines);