Wojciech Kozlowski
14a0567fa1
Closes #14 Reviewed-on: https://git.wojciechkozlowski.eu/wojtek/musichoard/pulls/17
94 lines
2.4 KiB
Rust
94 lines
2.4 KiB
Rust
use ratatui::backend::CrosstermBackend;
|
|
use ratatui::Terminal;
|
|
use std::io;
|
|
use std::path::PathBuf;
|
|
|
|
use structopt::StructOpt;
|
|
|
|
use musichoard::{
|
|
collection::MhCollectionManager,
|
|
database::json::{JsonDatabase, JsonDatabaseFileBackend},
|
|
library::beets::{BeetsLibrary, BeetsLibraryCommandExecutor},
|
|
};
|
|
|
|
mod tui;
|
|
use tui::{
|
|
app::App, event::EventChannel, handler::TuiEventHandler, listener::TuiEventListener, ui::Ui,
|
|
Tui,
|
|
};
|
|
|
|
#[derive(StructOpt)]
|
|
struct Opt {
|
|
#[structopt(
|
|
short = "b",
|
|
long = "beets",
|
|
name = "beets config file path",
|
|
parse(from_os_str)
|
|
)]
|
|
beets_config_file_path: Option<PathBuf>,
|
|
|
|
#[structopt(
|
|
short = "d",
|
|
long = "database",
|
|
name = "database file path",
|
|
default_value = "database.json",
|
|
parse(from_os_str)
|
|
)]
|
|
database_file_path: PathBuf,
|
|
}
|
|
|
|
fn main() {
|
|
// Create the application.
|
|
let opt = Opt::from_args();
|
|
|
|
let beets = BeetsLibrary::new(Box::new(
|
|
BeetsLibraryCommandExecutor::default().config(opt.beets_config_file_path.as_deref()),
|
|
));
|
|
|
|
let database = JsonDatabase::new(Box::new(JsonDatabaseFileBackend::new(
|
|
&opt.database_file_path,
|
|
)));
|
|
|
|
let collection_manager = MhCollectionManager::new(Box::new(beets), Box::new(database));
|
|
|
|
// Initialize the terminal user interface.
|
|
let backend = CrosstermBackend::new(io::stdout());
|
|
let terminal = Terminal::new(backend).expect("failed to initialise terminal");
|
|
|
|
let channel = EventChannel::new();
|
|
let listener = TuiEventListener::new(channel.sender());
|
|
let handler = TuiEventHandler::new(channel.receiver());
|
|
|
|
let ui = Ui::new();
|
|
|
|
let app = App::new(Box::new(collection_manager)).expect("failed to initialise app");
|
|
|
|
// Run the TUI application.
|
|
Tui::run(terminal, app, ui, handler, listener).expect("failed to run tui");
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[macro_use]
|
|
mod testlib;
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use mockall::mock;
|
|
use once_cell::sync::Lazy;
|
|
|
|
use musichoard::collection::{self, Collection, CollectionManager};
|
|
use musichoard::*;
|
|
|
|
pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| collection!());
|
|
|
|
mock! {
|
|
pub CollectionManager {}
|
|
|
|
impl CollectionManager for CollectionManager {
|
|
fn rescan_library(&mut self) -> Result<(), collection::Error>;
|
|
fn save_to_database(&mut self) -> Result<(), collection::Error>;
|
|
fn get_collection(&self) -> &Collection;
|
|
}
|
|
}
|
|
}
|