WIP: 93---musichoard-with-dyn-trait-or-generics #94
49
src/main.rs
49
src/main.rs
@ -2,9 +2,6 @@ use std::fs::OpenOptions;
|
||||
use std::path::PathBuf;
|
||||
use std::{ffi::OsString, io};
|
||||
|
||||
use musichoard::database::NoDatabase;
|
||||
use musichoard::library::NoLibrary;
|
||||
use musichoard::Collection;
|
||||
use ratatui::{backend::CrosstermBackend, Terminal};
|
||||
use structopt::StructOpt;
|
||||
|
||||
@ -66,31 +63,11 @@ fn with(lib: Option<Box<dyn ILibrary>>, db: Option<Box<dyn IDatabase>>) {
|
||||
Tui::run(terminal, ui, handler, listener).expect("failed to run tui");
|
||||
}
|
||||
|
||||
fn with_database(opt: Opt, db: Option<Box<dyn IDatabase>>) {
|
||||
if opt.no_library {
|
||||
with(None, db);
|
||||
} else if let Some(uri) = opt.beets_ssh_uri {
|
||||
let uri = uri.into_string().expect("invalid SSH URI");
|
||||
let beets_config_file_path = opt
|
||||
.beets_config_file_path
|
||||
.map(|s| s.into_string())
|
||||
.transpose()
|
||||
.expect("failed to extract beets config file path");
|
||||
let lib_exec = BeetsLibrarySshExecutor::new(uri)
|
||||
.expect("failed to initialise beets")
|
||||
.config(beets_config_file_path);
|
||||
with(Some(Box::new(BeetsLibrary::new(lib_exec))), db);
|
||||
} else {
|
||||
let lib_exec = BeetsLibraryProcessExecutor::default().config(opt.beets_config_file_path);
|
||||
with(Some(Box::new(BeetsLibrary::new(lib_exec))), db);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let opt = Opt::from_args();
|
||||
|
||||
if opt.no_database {
|
||||
with_database(opt, None);
|
||||
let database: Option<Box<dyn IDatabase>> = if opt.no_database {
|
||||
None
|
||||
} else {
|
||||
// Create an empty database file if it does not exist.
|
||||
match OpenOptions::new()
|
||||
@ -111,8 +88,28 @@ fn main() {
|
||||
}
|
||||
|
||||
let db_exec = JsonDatabaseFileBackend::new(&opt.database_file_path);
|
||||
with_database(opt, Some(Box::new(JsonDatabase::new(db_exec))));
|
||||
Some(Box::new(JsonDatabase::new(db_exec)))
|
||||
};
|
||||
|
||||
let library: Option<Box<dyn ILibrary>> = if opt.no_library {
|
||||
None
|
||||
} else if let Some(uri) = opt.beets_ssh_uri {
|
||||
let uri = uri.into_string().expect("invalid SSH URI");
|
||||
let beets_config_file_path = opt
|
||||
.beets_config_file_path
|
||||
.map(|s| s.into_string())
|
||||
.transpose()
|
||||
.expect("failed to extract beets config file path");
|
||||
let lib_exec = BeetsLibrarySshExecutor::new(uri)
|
||||
.expect("failed to initialise beets")
|
||||
.config(beets_config_file_path);
|
||||
Some(Box::new(BeetsLibrary::new(lib_exec)))
|
||||
} else {
|
||||
let lib_exec = BeetsLibraryProcessExecutor::default().config(opt.beets_config_file_path);
|
||||
Some(Box::new(BeetsLibrary::new(lib_exec)))
|
||||
};
|
||||
|
||||
with(library, database);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
Loading…
Reference in New Issue
Block a user