aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: e61a7719184d08e93afb80058742340700e01348 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
mod cli;
mod db;
mod gui;
mod model;
mod validation;

use anyhow::Result;
use clap::Parser;

#[derive(Parser)]
#[clap()]
struct Opt {
    /// Path of SQLite database in which to store events
    #[clap(long = "database", default_value = "database.sqlite3")]
    db_path: String,

    /// Started at events as plain text
    #[clap(long = "date")]
    date: Option<String>,

    /// Started between <timestamp..timestamp> events as plain text
    #[clap(long = "start-between")]
    start_between: Option<String>,
}

fn main() -> Result<()> {
    let Opt {
        db_path,
        date,
        start_between,
    } = Opt::parse();
    let conn = db::init(&db_path)?;

    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(())
}