Clean up command line args usage
This commit is contained in:
parent
9ffdfa1a77
commit
3f7b45efda
@ -1,5 +1,3 @@
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
use log::debug;
|
||||
use sqlx::{migrate::MigrateDatabase, Connection, Sqlite, SqliteConnection, SqlitePool};
|
||||
|
||||
|
26
src/main.rs
26
src/main.rs
@ -8,6 +8,7 @@ use clap::Parser;
|
||||
use database::Database;
|
||||
use env_logger::Env;
|
||||
use gtk::prelude::*;
|
||||
use log::error;
|
||||
use mcdu::McduModel;
|
||||
use relm4::prelude::*;
|
||||
use sheet_listing::{SheetListingInput, SheetListingModel};
|
||||
@ -98,7 +99,7 @@ impl SimpleComponent for AppModel {
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about)]
|
||||
struct Cli {
|
||||
directory: Option<PathBuf>,
|
||||
directory: PathBuf,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
@ -106,27 +107,16 @@ async fn main() {
|
||||
// dotenvy::dotenv().unwrap();
|
||||
env_logger::Builder::from_env(Env::default().default_filter_or("debug")).init();
|
||||
let cli = Cli::parse();
|
||||
if !cli.directory.is_dir() {
|
||||
error!("Sheet folder path is no dir or does not exist");
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
let database = Database::setup("./testdb.db").await.unwrap();
|
||||
|
||||
database.insert_sheet(Sheet::new_debug()).await.unwrap();
|
||||
// database.insert_sheet(Sheet::new_debug()).await.unwrap();
|
||||
let sheets = database.fetch_all_sheets().await.unwrap();
|
||||
println!("Sheets: {:?}", sheets);
|
||||
|
||||
let app = RelmApp::new("de.frajul.sheet-organizer");
|
||||
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
if args.len() <= 1 {
|
||||
eprintln!("Please provide sheet folder path");
|
||||
process::exit(1);
|
||||
}
|
||||
let file_path = PathBuf::from(&args[1]);
|
||||
if !file_path.is_dir() {
|
||||
eprintln!("Sheet folder path is no dir or does not exist");
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
// Pass empty command line args to allow my own parsing
|
||||
app.with_args(Vec::new()).run::<AppModel>(file_path);
|
||||
app.with_args(Vec::new()).run::<AppModel>(cli.directory);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user