Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include team name in header #6

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ┃
Expand All @@ -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 ┃
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ impl Config {
self.date_format.as_deref().unwrap_or(DEFAULT_DATE_FMT)
}

pub fn default_team(&self) -> Option<&Vec<Member>> {
pub fn default_team(&self) -> Option<(&str, &Vec<Member>)> {
match &self.default_team {
Some(name) => self.teams.get(name),
Some(name) => self.teams.get(name).map(|members| (name.as_str(), members)),
None => None,
}
}
Expand Down
25 changes: 17 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<String>("DATE") {
let date_string = date.cloned().collect::<String>();
Expand All @@ -108,23 +108,32 @@ fn main() {
Local::now()
};

let team = if matches.contains_id("ALL") {
None
let (name, team) = if matches.get_flag("ALL") {
(None, None)
} else if let Some(team) = matches.get_one::<String>("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);
}
}
}
Expand Down
Loading