Programm weitergeschrieben

This commit is contained in:
Damian Wessels
2025-05-14 15:15:32 +02:00
parent 3b120bb7d1
commit a6430a98f8
13 changed files with 489 additions and 50 deletions

View File

@@ -1,19 +1,25 @@
mod style;
mod commands;
mod config;
mod database;
mod entry;
mod state;
mod style;
mod utils;
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 anyhow::{Context, Result};
use clap::{ArgAction, Args, Parser, Subcommand};
use commands::*;
use config::Config;
use database::{connect_to_db, ensure_db_exists};
use directories::ProjectDirs;
pub use entry::Entry;
use langtime::parse;
pub use state::State;
#[derive(Parser, Debug)]
#[command(author,version, about, infer_subcommands = true)]
#[command(author, version, about, infer_subcommands = true)]
struct Cli {
#[command(subcommand)]
command: SubCommands,
@@ -36,9 +42,9 @@ enum SubCommands {
},
/// Display the current timesheet
Display {
/// Show an JSON
/// Show an JSON
#[arg(long)]
json:bool,
json: bool,
/// Show the Task IDs
#[arg(short, long)]
ids: bool,
@@ -50,10 +56,14 @@ enum SubCommands {
end: Option<String>,
/// Just filter by whole days, do not take into account the time
#[arg(short, long)]
filter_by_date:bool,
filter_by_date: bool,
/// The timesehet to display, or the current one
sheet:Option<String>,
}
sheet: Option<String>,
},
/// List available timesheet
List,
/// Shows the active task for the current sheet
Current,
}
fn main() {
@@ -63,7 +73,6 @@ fn main() {
}
}
fn cli() -> Result<()> {
let config = Config::build().context("Failed to build configuration")?;
setup(&config).context("Programmdatanbank konnte nicht erstellt werden")?;
@@ -72,6 +81,35 @@ fn cli() -> Result<()> {
let cli = Cli::parse();
match &cli.command {
SubCommands::In { task, at } => {
let target_time = at.as_ref().map(|at| parse(at)).transpose()?;
let task = task.as_ref();
let default_task = "".to_string();
let task = task.unwrap_or(&default_task);
start_task(task, target_time, &state).context("Could not start task")?;
}
SubCommands::Out { at } => {
let target_time = at.as_ref().map(|at| parse(at)).transpose()?;
stop_task(target_time, &mut state).context("Could not stop task")?;
}
SubCommands::Display {
json,
ids,
start,
end,
filter_by_date,
sheet,
} => {}
SubCommands::List => {
list_sheets(&state).context("Could not list sheets")?;
}
SubCommands::Current => {
current_task(&state).context("could not get current task")?;
}
}
Ok(())
}
@@ -81,4 +119,4 @@ fn setup(config: &Config) -> Result<()> {
let db = connect_to_db(config)?;
create_tables(&db)?;
Ok(())
}
}