Add some comments and add the fetch sub command
All checks were successful
Build and Publish / Build and Test (push) Successful in 6m39s

This commit is contained in:
Joshua Coles 2024-09-30 22:20:13 +01:00
parent 8e8fc6a64f
commit cfadd9f0aa

View File

@ -42,7 +42,7 @@ struct TableSummary {
tag_ids: Vec<u64>, tag_ids: Vec<u64>,
} }
use chrono::TimeDelta; use chrono::{NaiveDate, TimeDelta};
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use std::net::IpAddr; use std::net::IpAddr;
@ -64,6 +64,7 @@ struct Cli {
#[derive(Subcommand)] #[derive(Subcommand)]
enum Commands { enum Commands {
/// Start the built-in HTTP server
Server { Server {
#[arg(long, env = "IP", default_value = "127.0.0.1")] #[arg(long, env = "IP", default_value = "127.0.0.1")]
ip: IpAddr, ip: IpAddr,
@ -72,9 +73,17 @@ enum Commands {
port: u16, port: u16,
}, },
/// Migrate the database without performing any other actions
Migrate, Migrate,
/// Sync changes since the database was last updated, with a default look-back of 30 days
Sync, Sync,
/// Fetch time entries within a date range
Fetch {
since: NaiveDate,
until: NaiveDate,
},
} }
#[tokio::main] #[tokio::main]
@ -102,14 +111,26 @@ async fn main() {
let worker = Worker { db, toggl_api }; let worker = Worker { db, toggl_api };
if let Commands::Server { ip, port } = cli.command { match cli.command {
server::serve(worker, ip, port) Commands::Server { ip, port } => {
.await server::serve(worker, ip, port)
.expect("Failed to start server"); .await
} else { .expect("Failed to start server");
worker }
.update(TimeDelta::days(30)) Commands::Sync => {
.await worker
.expect("Failed to update 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"),
} }
} }