commit dd669f8d2d50ae743feb07c3253396758640ad73 Author: Damian Wessels Date: Tue May 13 22:23:54 2025 +0200 First diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/database.rs b/src/database.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..55e2f05 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,84 @@ +mod style; +mod config; +mod database; +mod state; + +use database::{ensure_db_exists, connect_to_db}; +use config::Config; +use anyhow::{Result, Context}; +use clap::{ArgAction, Args, Parser, Subcommand}; +use crate::database::create_tables; +use crate::style::{style_string, Styles}; +pub use state::State; +use langtime::parse; + +#[derive(Parser, Debug)] +#[command(author,version, about, infer_subcommands = true)] +struct Cli { + #[command(subcommand)] + command: SubCommands, +} + +#[derive(Subcommand, Debug)] +enum SubCommands { + /// Checks into the current timesheet + In { + /// Task description + task: Option, + /// The time and date when this Task was Started + #[arg(short, long)] + at: Option, + }, + /// Checks out of the current timesheet + Out { + #[arg(short, long)] + at: Option, + }, + /// Display the current timesheet + Display { + /// Show an JSON + #[arg(long)] + json:bool, + /// Show the Task IDs + #[arg(short, long)] + ids: bool, + /// Filter the thask based on when they started + #[arg(short, long)] + start: Option, + /// Filter the tasks based on when they ended + #[arg(short, long)] + end: Option, + /// Just filter by whole days, do not take into account the time + #[arg(short, long)] + filter_by_date:bool, + /// The timesehet to display, or the current one + sheet:Option, + } +} + +fn main() { + if let Err(e) = cli() { + println!("{} {}", style_string("Error: ", Styles::Error), e); + std::process::exit(1); + } +} + + +fn cli() -> Result<()> { + let config = Config::build().context("Failed to build configuration")?; + setup(&config).context("Programmdatanbank konnte nicht erstellt werden")?; + + let mut state = State::build(&config).context("Could not load the programm state")?; + + let cli = Cli::parse(); + + + Ok(()) +} + +fn setup(config: &Config) -> Result<()> { + ensure_db_exists(config)?; + let db = connect_to_db(config)?; + create_tables(&db)?; + Ok(()) +} \ No newline at end of file diff --git a/src/state.rs b/src/state.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/style.rs b/src/style.rs new file mode 100644 index 0000000..e69de29