Fix with_ function naming in main
This commit is contained in:
parent
845e9b09f4
commit
acdd3ba8ed
74
src/main.rs
74
src/main.rs
@ -1,28 +1,25 @@
|
|||||||
use std::fs::OpenOptions;
|
use std::{ffi::OsString, fs::OpenOptions, io, path::PathBuf};
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::{ffi::OsString, io};
|
|
||||||
|
|
||||||
use musichoard::database::NullDatabase;
|
|
||||||
use musichoard::library::{ILibrary, NullLibrary};
|
|
||||||
use musichoard::{Collection, MusicHoardBuilder};
|
|
||||||
use ratatui::{backend::CrosstermBackend, Terminal};
|
use ratatui::{backend::CrosstermBackend, Terminal};
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
use musichoard::{
|
use musichoard::{
|
||||||
database::{
|
database::{
|
||||||
json::{backend::JsonDatabaseFileBackend, JsonDatabase},
|
json::{backend::JsonDatabaseFileBackend, JsonDatabase},
|
||||||
IDatabase,
|
IDatabase, NullDatabase,
|
||||||
},
|
},
|
||||||
library::beets::{
|
library::{
|
||||||
|
beets::{
|
||||||
executor::{ssh::BeetsLibrarySshExecutor, BeetsLibraryProcessExecutor},
|
executor::{ssh::BeetsLibrarySshExecutor, BeetsLibraryProcessExecutor},
|
||||||
BeetsLibrary,
|
BeetsLibrary,
|
||||||
},
|
},
|
||||||
NoLibrary,
|
ILibrary, NullLibrary,
|
||||||
|
},
|
||||||
|
Collection, MusicHoardBuilder, NoDatabase, NoLibrary,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod tui;
|
mod tui;
|
||||||
use tui::ui::Ui;
|
use tui::{event::EventChannel, handler::EventHandler, listener::EventListener, ui::Ui, Tui};
|
||||||
use tui::{event::EventChannel, handler::EventHandler, listener::EventListener, Tui};
|
|
||||||
|
|
||||||
#[derive(StructOpt)]
|
#[derive(StructOpt)]
|
||||||
struct Opt {
|
struct Opt {
|
||||||
@ -63,32 +60,9 @@ fn with<LIB: ILibrary, DB: IDatabase>(builder: MusicHoardBuilder<LIB, DB>) {
|
|||||||
Tui::run(terminal, ui, handler, listener).expect("failed to run tui");
|
Tui::run(terminal, ui, handler, listener).expect("failed to run tui");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_database<DB: IDatabase>(opt: Opt, builder: MusicHoardBuilder<NoLibrary, DB>) {
|
fn with_database<LIB: ILibrary>(opt: Opt, builder: MusicHoardBuilder<LIB, NoDatabase>) {
|
||||||
if opt.no_library {
|
|
||||||
with(builder.set_library(NullLibrary));
|
|
||||||
} 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(builder.set_library(BeetsLibrary::new(lib_exec)));
|
|
||||||
} else {
|
|
||||||
let lib_exec = BeetsLibraryProcessExecutor::default().config(opt.beets_config_file_path);
|
|
||||||
with(builder.set_library(BeetsLibrary::new(lib_exec)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let opt = Opt::from_args();
|
|
||||||
let builder = MusicHoardBuilder::default();
|
|
||||||
|
|
||||||
if opt.no_database {
|
if opt.no_database {
|
||||||
with_database(opt, builder.set_database(NullDatabase));
|
with(builder.set_database(NullDatabase));
|
||||||
} else {
|
} else {
|
||||||
// Create an empty database file if it does not exist.
|
// Create an empty database file if it does not exist.
|
||||||
match OpenOptions::new()
|
match OpenOptions::new()
|
||||||
@ -109,10 +83,36 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let db_exec = JsonDatabaseFileBackend::new(&opt.database_file_path);
|
let db_exec = JsonDatabaseFileBackend::new(&opt.database_file_path);
|
||||||
with_database(opt, builder.set_database(JsonDatabase::new(db_exec)));
|
with(builder.set_database(JsonDatabase::new(db_exec)));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn with_library(opt: Opt, builder: MusicHoardBuilder<NoLibrary, NoDatabase>) {
|
||||||
|
if opt.no_library {
|
||||||
|
with_database(opt, builder.set_library(NullLibrary));
|
||||||
|
} 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_database(opt, builder.set_library(BeetsLibrary::new(lib_exec)));
|
||||||
|
} else {
|
||||||
|
let lib_exec = BeetsLibraryProcessExecutor::default().config(opt.beets_config_file_path);
|
||||||
|
with_database(opt, builder.set_library(BeetsLibrary::new(lib_exec)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let opt = Opt::from_args();
|
||||||
|
let builder = MusicHoardBuilder::default();
|
||||||
|
with_library(opt, builder);
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod testlib;
|
mod testlib;
|
||||||
|
Loading…
Reference in New Issue
Block a user