First
This commit is contained in:
0
src/config.rs
Normal file
0
src/config.rs
Normal file
0
src/database.rs
Normal file
0
src/database.rs
Normal file
84
src/main.rs
Normal file
84
src/main.rs
Normal file
@@ -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<String>,
|
||||
/// The time and date when this Task was Started
|
||||
#[arg(short, long)]
|
||||
at: Option<String>,
|
||||
},
|
||||
/// Checks out of the current timesheet
|
||||
Out {
|
||||
#[arg(short, long)]
|
||||
at: Option<String>,
|
||||
},
|
||||
/// 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<String>,
|
||||
/// Filter the tasks based on when they ended
|
||||
#[arg(short, long)]
|
||||
end: Option<String>,
|
||||
/// 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<String>,
|
||||
}
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
0
src/state.rs
Normal file
0
src/state.rs
Normal file
0
src/style.rs
Normal file
0
src/style.rs
Normal file
Reference in New Issue
Block a user