From cfadd9f0aa3fd9e8f7dbdb542d9c065074a247ee Mon Sep 17 00:00:00 2001 From: Joshua Coles Date: Mon, 30 Sep 2024 22:20:13 +0100 Subject: [PATCH] Add some comments and add the fetch sub command --- src/main.rs | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8fd58e2..2eaf2f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,7 +42,7 @@ struct TableSummary { tag_ids: Vec, } -use chrono::TimeDelta; +use chrono::{NaiveDate, TimeDelta}; use clap::{Parser, Subcommand}; use std::net::IpAddr; @@ -64,6 +64,7 @@ struct Cli { #[derive(Subcommand)] enum Commands { + /// Start the built-in HTTP server Server { #[arg(long, env = "IP", default_value = "127.0.0.1")] ip: IpAddr, @@ -72,9 +73,17 @@ enum Commands { port: u16, }, + /// Migrate the database without performing any other actions Migrate, + /// Sync changes since the database was last updated, with a default look-back of 30 days Sync, + + /// Fetch time entries within a date range + Fetch { + since: NaiveDate, + until: NaiveDate, + }, } #[tokio::main] @@ -102,14 +111,26 @@ async fn main() { let worker = Worker { db, toggl_api }; - if let Commands::Server { ip, port } = cli.command { - server::serve(worker, ip, port) - .await - .expect("Failed to start server"); - } else { - worker - .update(TimeDelta::days(30)) - .await - .expect("Failed to update worker"); + match cli.command { + Commands::Server { ip, port } => { + server::serve(worker, ip, port) + .await + .expect("Failed to start server"); + } + Commands::Sync => { + worker + .update(TimeDelta::days(30)) + .await + .expect("Failed to update worker"); + } + + Commands::Fetch { since, until } => { + worker + .fetch_within(since, until) + .await + .expect("Failed to fetch worker"); + } + + Commands::Migrate => unreachable!("Migrate should have returned early"), } }