Add some comments and add the fetch sub command
All checks were successful
Build and Publish / Build and Test (push) Successful in 6m39s
All checks were successful
Build and Publish / Build and Test (push) Successful in 6m39s
This commit is contained in:
parent
8e8fc6a64f
commit
cfadd9f0aa
41
src/main.rs
41
src/main.rs
@ -42,7 +42,7 @@ struct TableSummary {
|
||||
tag_ids: Vec<u64>,
|
||||
}
|
||||
|
||||
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"),
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user