aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md8
-rw-r--r--src/cli/mod.rs21
-rw-r--r--src/main.rs21
3 files changed, 40 insertions, 10 deletions
diff --git a/README.md b/README.md
index 15206f0..2986378 100644
--- a/README.md
+++ b/README.md
@@ -18,14 +18,10 @@ cargo test
## V1
-### API
-
-1. Get list of today’s events.
-
### Repeat events
-1. Update / delete specific repetition occurences.
-2. When validating repetition, don’t produce None if there is a validation error.
+1. When validating repetition, don’t produce None if there is a validation error.
+2. Update / delete specific repetition occurences.
### Navigate around
diff --git a/src/cli/mod.rs b/src/cli/mod.rs
new file mode 100644
index 0000000..862bcbe
--- /dev/null
+++ b/src/cli/mod.rs
@@ -0,0 +1,21 @@
+use anyhow::Result;
+use chrono::Local;
+use rusqlite::Connection;
+
+use crate::{db, model::event, model::event::Event};
+
+pub fn today(conn: &Connection) -> Result<String> {
+ let today = Local::today().naive_local();
+ let mut events = db::list_non_repeated_between(conn, today, today)?;
+ let repeated_events = db::list_repeated(conn)?;
+ let repetitions = event::repetitions_between(&repeated_events, today, today);
+ for repetition in repetitions.values().flatten() {
+ events.push(repetition.clone());
+ }
+ events.sort_by_key(|e| e.start);
+ Ok(events
+ .iter()
+ .map(Event::pprint)
+ .collect::<Vec<String>>()
+ .join("\n"))
+}
diff --git a/src/main.rs b/src/main.rs
index 956e930..1f5a294 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,4 @@
+mod cli;
mod db;
mod gui;
mod model;
@@ -8,13 +9,25 @@ use structopt::StructOpt;
#[derive(StructOpt)]
#[structopt()]
struct Opt {
- #[structopt(long, default_value = "database.db")]
- database: String,
+ /// Path of SQLite database in which to store events
+ #[structopt(long = "database", default_value = "database.db")]
+ db_path: String,
+
+ /// List today’s events as plain text
+ #[structopt(long = "list-today")]
+ list_today: bool,
}
fn main() -> Result<()> {
- let db_path = Opt::from_args().database;
+ let Opt {
+ db_path,
+ list_today,
+ } = Opt::from_args();
let conn = db::init(&db_path)?;
- gui::run(conn);
+ if list_today {
+ print!("{}", cli::today(&conn)?);
+ } else {
+ gui::run(conn);
+ }
Ok(())
}