Skip to content

Commit

Permalink
added more cli options for the today subcommand, ironically you can v…
Browse files Browse the repository at this point in the history
…iew yesterday with the today command
  • Loading branch information
anesthetice committed May 26, 2024
1 parent a9a5e00 commit 9e96e22
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "syracuse"
version = "2.1.1"
version = "2.1.2"
edition = "2021"

[dependencies]
Expand Down
33 changes: 31 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,22 @@ pub fn cli() -> clap::Command {
.alias("all")
.alias("full")
.action(ArgAction::SetTrue)
)
.arg(
Arg::new("yesterday")
.required(false)
.short('y')
.long("yesterday")
.action(ArgAction::SetTrue)
)
.arg(
Arg::new("previous")
.required(false)
.short('p')
.long("previous")
.alias("prev")
.value_parser(value_parser!(usize))
.action(ArgAction::Set)
);

let backup_subcommand = Command::new("backup")
Expand Down Expand Up @@ -369,18 +385,31 @@ pub fn process_today_subcommand(arg_matches: &ArgMatches, entries: &Entries, tod
return Ok(PO::Continue(None))
};

let date: SyrDate = {
let mut date = **today;
if arg_matches.get_flag("yesterday") {
date = date.previous_day().ok_or(error::Error{}).context("failed to get yesterday's date, this should not occur")?;
}
else if let Some(val) = arg_matches.get_one::<usize>("previous") {
for _ in 0..*val {
date = date.previous_day().ok_or(error::Error{}).context("failed to get the previous date, this should not occur")?
}
}
date.into()
};

let sum = {
if arg_matches.get_flag("explicit") {
entries.iter().map(|entry| {
let duration = entry.get_block_duration(today);
let duration = entry.get_block_duration(&date);
// 15 seems reasonable, I could check the length of every entry's name and get a better estimation
// but even that would not be perfect, I would have to count the valid grapheme clusters which adds a lot of complexity
// to what I itend as simple padding
if duration != 0 {println!("{:<15} : {}", entry.get_name(), ns_to_pretty_string(duration))}
duration
}).sum()
} else {
entries.iter().map(|entry| entry.get_block_duration(today)).sum()
entries.iter().map(|entry| entry.get_block_duration(&date)).sum()
}
};

Expand Down

0 comments on commit 9e96e22

Please sign in to comment.