71 lines
1.8 KiB
Rust
71 lines
1.8 KiB
Rust
mod config;
|
|
mod database;
|
|
mod sheet;
|
|
mod sheet_dao;
|
|
mod sheet_validation;
|
|
mod ui;
|
|
|
|
use std::{path::PathBuf, process};
|
|
|
|
use clap::Parser;
|
|
use config::Config;
|
|
use database::Database;
|
|
use env_logger::Env;
|
|
use log::{error, warn};
|
|
use relm4::RelmApp;
|
|
|
|
use crate::ui::app::{AppInitData, AppModel};
|
|
|
|
#[derive(Parser)]
|
|
#[command(author, version, about)]
|
|
struct Cli {
|
|
working_directory: Option<PathBuf>,
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
env_logger::Builder::from_env(Env::default().default_filter_or("debug")).init();
|
|
|
|
let mut config = match config::load_config("sheet-organizer", "config.toml") {
|
|
Ok(config) => config,
|
|
Err(err) => {
|
|
warn!("Could not get configuration: {:#}", err);
|
|
Config::default()
|
|
}
|
|
};
|
|
|
|
let cli = Cli::parse();
|
|
// Overwrite config by cli options if specified
|
|
if cli.working_directory.is_some() {
|
|
config.working_directory = cli.working_directory;
|
|
}
|
|
|
|
let working_directory = config.working_directory.unwrap_or_else(|| {
|
|
error!("No working directory specified, neither in config nor in cli. Exiting...");
|
|
process::exit(1);
|
|
});
|
|
if !working_directory.is_dir() {
|
|
error!(
|
|
"Working directory '{}' does not exist",
|
|
working_directory.to_string_lossy()
|
|
);
|
|
process::exit(1);
|
|
}
|
|
|
|
let database = Database::setup(working_directory.join("database.sqlite"))
|
|
.await
|
|
.unwrap();
|
|
|
|
let sheets = sheet_validation::load_and_validate_sheets(&database, &working_directory).await;
|
|
|
|
let app_init_data = AppInitData {
|
|
sheets,
|
|
database,
|
|
directory: working_directory,
|
|
};
|
|
let app = RelmApp::new("de.frajul.sheet-organizer");
|
|
// Pass empty command line args to allow my own parsing
|
|
app.with_args(Vec::new())
|
|
.run_async::<AppModel>(app_init_data);
|
|
}
|