//! A simple invoice generator script #![allow(warnings)] #[macro_use] extern crate log; #[macro_use] extern crate libko; mod base; mod cli; mod pfile; pub(crate) use base::*; pub(crate) use cli::*; pub(crate) use pfile::*; use env_logger::Builder; use libko::*; use std::{fs::OpenOptions as Oo, io::Write}; fn main() { log_util::initialise(); let AppState { meta, cmd } = cli::parse(); match cmd { Command::Init => init(meta), Command::Generate => generate(meta), Command::Install => todo!(), Command::Set(k, v) => set(meta, k, v), } } /// Initialise a new project invoice with a a metadata set fn init(meta: Meta) { let pid = meta .project_id .as_ref() .unwrap_or_else(|| match meta.timefile.as_ref() { Some(tf) => match tf.client().as_ref() { Some(c) => c, None => fatal!("No project id given; timefile has no 'project' key!"), }, None => fatal!("No project id given; no timefile available"), }); let path = meta.invoice_dir.join(pid); let invoice_id = meta.new_invoice_id(); // let mut f = match Oo::new().write(true).truncate(true).open(path.clone()) { // Ok(f) => f, // _ => fatal!( // "Failed to create directory {}", // path.to_str().expect("Path contained non UTF-8 :(") // ), // }; // f.write_all(pfile::data_templ(&meta).as_bytes()).unwrap(); } fn generate(meta: Meta) {} fn set(meta: Meta, k: String, v: Option) { meta.update_config(k, v); }