Move database and library implementations out of core #162
@ -31,12 +31,12 @@ default = ["database-json", "library-beets"]
|
||||
bin = ["structopt"]
|
||||
database-json = ["serde", "serde_json"]
|
||||
library-beets = []
|
||||
ssh-library = ["openssh", "tokio"]
|
||||
library-beets-ssh = ["openssh", "tokio"]
|
||||
tui = ["aho-corasick", "crossterm", "once_cell", "ratatui"]
|
||||
|
||||
[[bin]]
|
||||
name = "musichoard"
|
||||
required-features = ["bin", "database-json", "library-beets", "ssh-library", "tui"]
|
||||
required-features = ["bin", "database-json", "library-beets", "library-beets-ssh", "tui"]
|
||||
|
||||
[[bin]]
|
||||
name = "musichoard-edit"
|
||||
|
@ -1,10 +1,5 @@
|
||||
//! Module for storing MusicHoard data in a database.
|
||||
|
||||
#[cfg(feature = "database-json")]
|
||||
pub mod json;
|
||||
#[cfg(feature = "database-json")]
|
||||
mod serde;
|
||||
|
||||
use std::fmt;
|
||||
|
||||
#[cfg(test)]
|
@ -1,8 +1,5 @@
|
||||
//! Module for interacting with the music library.
|
||||
|
||||
#[cfg(feature = "library-beets")]
|
||||
pub mod beets;
|
||||
|
||||
use std::{collections::HashSet, fmt, num::ParseIntError, str::Utf8Error};
|
||||
|
||||
#[cfg(test)]
|
||||
@ -59,26 +56,16 @@ pub enum Field {
|
||||
}
|
||||
|
||||
/// A library query. Can include or exclude particular fields.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[derive(Debug, Default, PartialEq, Eq)]
|
||||
pub struct Query {
|
||||
include: HashSet<Field>,
|
||||
exclude: HashSet<Field>,
|
||||
}
|
||||
|
||||
impl Default for Query {
|
||||
/// Create an empty query.
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
pub include: HashSet<Field>,
|
||||
pub exclude: HashSet<Field>,
|
||||
}
|
||||
|
||||
impl Query {
|
||||
/// Create an empty query.
|
||||
pub fn new() -> Self {
|
||||
Query {
|
||||
include: HashSet::new(),
|
||||
exclude: HashSet::new(),
|
||||
}
|
||||
Query::default()
|
||||
}
|
||||
|
||||
/// Refine the query to include a particular search term.
|
@ -2,7 +2,7 @@ use once_cell::sync::Lazy;
|
||||
|
||||
use crate::core::{
|
||||
collection::{album::AlbumMonth, track::TrackFormat},
|
||||
library::Item,
|
||||
interface::library::Item,
|
||||
};
|
||||
|
||||
pub static LIBRARY_ITEMS: Lazy<Vec<Item>> = Lazy::new(|| -> Vec<Item> {
|
2
src/core/interface/mod.rs
Normal file
2
src/core/interface/mod.rs
Normal file
@ -0,0 +1,2 @@
|
||||
pub mod database;
|
||||
pub mod library;
|
@ -1,6 +1,5 @@
|
||||
pub mod collection;
|
||||
pub mod database;
|
||||
pub mod library;
|
||||
pub mod interface;
|
||||
pub mod musichoard;
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -6,7 +6,10 @@ pub mod musichoard_builder;
|
||||
|
||||
use std::fmt::{self, Display};
|
||||
|
||||
use crate::core::{collection, database, library};
|
||||
use crate::core::{
|
||||
collection,
|
||||
interface::{database, library},
|
||||
};
|
||||
|
||||
/// Error type for `musichoard`.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
|
@ -8,8 +8,10 @@ use crate::core::{
|
||||
track::{Track, TrackId, TrackNum, TrackQuality},
|
||||
Collection, MergeCollections,
|
||||
},
|
||||
database::IDatabase,
|
||||
library::{ILibrary, Item, Query},
|
||||
interface::{
|
||||
database::IDatabase,
|
||||
library::{ILibrary, Item, Query},
|
||||
},
|
||||
musichoard::Error,
|
||||
};
|
||||
|
||||
@ -468,8 +470,10 @@ mod tests {
|
||||
|
||||
use crate::core::{
|
||||
collection::{artist::ArtistId, musicbrainz::MusicBrainz},
|
||||
database::{self, MockIDatabase},
|
||||
library::{self, testmod::LIBRARY_ITEMS, MockILibrary},
|
||||
interface::{
|
||||
database::{self, MockIDatabase},
|
||||
library::{self, testmod::LIBRARY_ITEMS, MockILibrary},
|
||||
},
|
||||
testmod::{FULL_COLLECTION, LIBRARY_COLLECTION},
|
||||
};
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::{
|
||||
core::{
|
||||
database::IDatabase,
|
||||
library::ILibrary,
|
||||
interface::{database::IDatabase, library::ILibrary},
|
||||
musichoard::musichoard::{MusicHoard, NoDatabase, NoLibrary},
|
||||
},
|
||||
Error,
|
||||
@ -79,7 +78,7 @@ impl<LIB: ILibrary, DB: IDatabase> MusicHoardBuilder<LIB, DB> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::core::{database::NullDatabase, library::NullLibrary};
|
||||
use crate::core::interface::{database::NullDatabase, library::NullLibrary};
|
||||
|
||||
use super::*;
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::core::database::json::IJsonDatabaseBackend;
|
||||
use crate::database::json::IJsonDatabaseBackend;
|
||||
|
||||
/// JSON database backend that uses a local file for persistent storage.
|
||||
pub struct JsonDatabaseFileBackend {
|
@ -7,7 +7,7 @@ use mockall::automock;
|
||||
|
||||
use crate::core::{
|
||||
collection::Collection,
|
||||
database::{IDatabase, LoadError, SaveError},
|
||||
interface::database::{IDatabase, LoadError, SaveError},
|
||||
};
|
||||
|
||||
use super::serde::{deserialize::DeserializeDatabase, serialize::SerializeDatabase};
|
4
src/database/mod.rs
Normal file
4
src/database/mod.rs
Normal file
@ -0,0 +1,4 @@
|
||||
#[cfg(feature = "database-json")]
|
||||
pub mod json;
|
||||
#[cfg(feature = "database-json")]
|
||||
mod serde;
|
@ -9,7 +9,7 @@ use crate::core::{
|
||||
musicbrainz::MusicBrainz,
|
||||
Collection,
|
||||
},
|
||||
database::LoadError,
|
||||
interface::database::LoadError,
|
||||
};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
@ -1,10 +1,11 @@
|
||||
//! MusicHoard - a music collection manager.
|
||||
|
||||
mod core;
|
||||
pub mod database;
|
||||
pub mod library;
|
||||
|
||||
pub use core::collection;
|
||||
pub use core::database;
|
||||
pub use core::library;
|
||||
pub use core::interface;
|
||||
|
||||
pub use core::musichoard::{
|
||||
musichoard::{MusicHoard, NoDatabase, NoLibrary},
|
||||
|
@ -8,7 +8,8 @@ use std::{
|
||||
str,
|
||||
};
|
||||
|
||||
use crate::core::library::{beets::IBeetsLibraryExecutor, Error};
|
||||
use crate::core::interface::library::Error;
|
||||
use crate::library::beets::IBeetsLibraryExecutor;
|
||||
|
||||
const BEET_DEFAULT: &str = "beet";
|
||||
|
||||
@ -74,7 +75,7 @@ impl IBeetsLibraryExecutor for BeetsLibraryProcessExecutor {
|
||||
impl IBeetsLibraryExecutorPrivate for BeetsLibraryProcessExecutor {}
|
||||
|
||||
// GRCOV_EXCL_START
|
||||
#[cfg(feature = "ssh-library")]
|
||||
#[cfg(feature = "library-beets-ssh")]
|
||||
pub mod ssh {
|
||||
//! Module for interacting with the music library via
|
||||
//! [beets](https://beets.readthedocs.io/en/stable/) over SSH.
|
@ -8,7 +8,7 @@ use mockall::automock;
|
||||
|
||||
use crate::core::{
|
||||
collection::track::TrackFormat,
|
||||
library::{Error, Field, ILibrary, Item, Query},
|
||||
interface::library::{Error, Field, ILibrary, Item, Query},
|
||||
};
|
||||
|
||||
macro_rules! list_format_separator {
|
||||
@ -201,7 +201,7 @@ mod testmod;
|
||||
mod tests {
|
||||
use mockall::predicate;
|
||||
|
||||
use crate::{collection::album::AlbumMonth, core::library::testmod::LIBRARY_ITEMS};
|
||||
use crate::{collection::album::AlbumMonth, core::interface::library::testmod::LIBRARY_ITEMS};
|
||||
|
||||
use super::*;
|
||||
use testmod::LIBRARY_BEETS;
|
2
src/library/mod.rs
Normal file
2
src/library/mod.rs
Normal file
@ -0,0 +1,2 @@
|
||||
#[cfg(feature = "library-beets")]
|
||||
pub mod beets;
|
16
src/main.rs
16
src/main.rs
@ -10,16 +10,14 @@ use ratatui::{backend::CrosstermBackend, Terminal};
|
||||
use structopt::StructOpt;
|
||||
|
||||
use musichoard::{
|
||||
database::{
|
||||
json::{backend::JsonDatabaseFileBackend, JsonDatabase},
|
||||
IDatabase, NullDatabase,
|
||||
database::json::{backend::JsonDatabaseFileBackend, JsonDatabase},
|
||||
interface::{
|
||||
database::{IDatabase, NullDatabase},
|
||||
library::{ILibrary, NullLibrary},
|
||||
},
|
||||
library::{
|
||||
beets::{
|
||||
executor::{ssh::BeetsLibrarySshExecutor, BeetsLibraryProcessExecutor},
|
||||
BeetsLibrary,
|
||||
},
|
||||
ILibrary, NullLibrary,
|
||||
library::beets::{
|
||||
executor::{ssh::BeetsLibrarySshExecutor, BeetsLibraryProcessExecutor},
|
||||
BeetsLibrary,
|
||||
},
|
||||
MusicHoardBuilder, NoDatabase, NoLibrary,
|
||||
};
|
||||
|
@ -1,4 +1,7 @@
|
||||
use musichoard::{collection::Collection, database::IDatabase, library::ILibrary, MusicHoard};
|
||||
use musichoard::{
|
||||
collection::Collection, interface::database::IDatabase, interface::library::ILibrary,
|
||||
MusicHoard,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
use mockall::automock;
|
||||
|
@ -5,10 +5,8 @@ use tempfile::NamedTempFile;
|
||||
|
||||
use musichoard::{
|
||||
collection::{album::AlbumDate, artist::Artist, Collection},
|
||||
database::{
|
||||
json::{backend::JsonDatabaseFileBackend, JsonDatabase},
|
||||
IDatabase,
|
||||
},
|
||||
database::json::{backend::JsonDatabaseFileBackend, JsonDatabase},
|
||||
interface::database::IDatabase,
|
||||
};
|
||||
|
||||
use crate::testlib::COLLECTION;
|
||||
|
@ -7,9 +7,9 @@ use std::{
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use musichoard::library::{
|
||||
beets::{executor::BeetsLibraryProcessExecutor, BeetsLibrary},
|
||||
Field, ILibrary, Item, Query,
|
||||
use musichoard::{
|
||||
interface::library::{Field, ILibrary, Item, Query},
|
||||
library::beets::{executor::BeetsLibraryProcessExecutor, BeetsLibrary},
|
||||
};
|
||||
|
||||
use crate::library::testmod::LIBRARY_ITEMS;
|
||||
|
@ -2,7 +2,7 @@ use once_cell::sync::Lazy;
|
||||
|
||||
use musichoard::{
|
||||
collection::{album::AlbumMonth, track::TrackFormat},
|
||||
library::Item,
|
||||
interface::library::Item,
|
||||
};
|
||||
|
||||
pub static LIBRARY_ITEMS: Lazy<Vec<Item>> = Lazy::new(|| -> Vec<Item> {
|
||||
|
Loading…
Reference in New Issue
Block a user