aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--src/cli/mod.rs17
-rw-r--r--src/main.rs20
3 files changed, 25 insertions, 16 deletions
diff --git a/README.md b/README.md
index 43eccf4..8f54d46 100644
--- a/README.md
+++ b/README.md
@@ -30,10 +30,10 @@ Run tests with:
cargo test
```
-Get today’s events with:
+Show options:
```bash
-cargo run -- --list-today
+cargo run -- --help
```
# TODO
diff --git a/src/cli/mod.rs b/src/cli/mod.rs
index 3674a08..aa54c08 100644
--- a/src/cli/mod.rs
+++ b/src/cli/mod.rs
@@ -1,13 +1,22 @@
use anyhow::Result;
-use chrono::{Local, NaiveDate, NaiveDateTime, TimeZone};
+use chrono::{Local, NaiveDate, NaiveDateTime, TimeDelta, TimeZone};
use rusqlite::Connection;
+use std::ops::{Add, Sub};
use crate::model::event::Event;
use crate::{db, model::event};
-pub fn today(conn: &Connection) -> Result<String> {
- let today = Local::now().date_naive();
- let events = between_inclusive(conn, today, today)?;
+pub fn parse_date(s: String) -> Option<NaiveDate> {
+ match s.as_str() {
+ "yesterday" => Some(Local::now().sub(TimeDelta::days(1)).date_naive()),
+ "today" => Some(Local::now().date_naive()),
+ "tomorrow" => Some(Local::now().add(TimeDelta::days(1)).date_naive()),
+ _ => NaiveDate::parse_from_str(&s, "%Y-%m-%d").ok(),
+ }
+}
+
+pub fn started_at_date(conn: &Connection, date: NaiveDate) -> Result<String> {
+ let events = between_inclusive(conn, date, date)?;
Ok(format_events(events))
}
diff --git a/src/main.rs b/src/main.rs
index 8eafd77..e61a771 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -14,11 +14,11 @@ struct Opt {
#[clap(long = "database", default_value = "database.sqlite3")]
db_path: String,
- /// List today’s events as plain text
- #[clap(long = "list-today")]
- list_today: bool,
+ /// Started at events as plain text
+ #[clap(long = "date")]
+ date: Option<String>,
- /// Start between <timestamp..timestamp> events as plain text
+ /// Started between <timestamp..timestamp> events as plain text
#[clap(long = "start-between")]
start_between: Option<String>,
}
@@ -26,17 +26,17 @@ struct Opt {
fn main() -> Result<()> {
let Opt {
db_path,
- list_today,
+ date,
start_between,
} = Opt::parse();
let conn = db::init(&db_path)?;
- if list_today {
- print!("{}", cli::today(&conn)?);
- } else {
- match start_between.and_then(cli::parse_timestamp_range) {
+
+ match date.and_then(cli::parse_date) {
+ Some(date) => print!("{}", cli::started_at_date(&conn, date)?),
+ None => match start_between.and_then(cli::parse_timestamp_range) {
Some((from, to)) => print!("{}", cli::start_between(&conn, from, to)?),
None => gui::run(conn),
- }
+ },
};
Ok(())
}