Split lib.rs into smaller files #115
@ -1,10 +1,12 @@
|
||||
use paste::paste;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use paste::paste;
|
||||
use structopt::{clap::AppSettings, StructOpt};
|
||||
|
||||
use musichoard::{
|
||||
collection::artist::ArtistId,
|
||||
database::json::{backend::JsonDatabaseFileBackend, JsonDatabase},
|
||||
ArtistId, MusicHoard, MusicHoardBuilder, NoLibrary,
|
||||
MusicHoard, MusicHoardBuilder, NoLibrary,
|
||||
};
|
||||
|
||||
type MH = MusicHoard<NoLibrary, JsonDatabase<JsonDatabaseFileBackend>>;
|
||||
|
@ -1,9 +1,11 @@
|
||||
use core::mem;
|
||||
use std::mem;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::merge::{Merge, MergeSorted};
|
||||
use super::track::Track;
|
||||
use crate::core::collection::{
|
||||
merge::{Merge, MergeSorted},
|
||||
track::Track,
|
||||
};
|
||||
|
||||
/// An album is a collection of tracks that were released together.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
|
||||
|
@ -8,9 +8,11 @@ use serde::{Deserialize, Serialize};
|
||||
use url::Url;
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::album::Album;
|
||||
use super::merge::{Merge, MergeSorted};
|
||||
use super::Error;
|
||||
use crate::core::collection::{
|
||||
album::Album,
|
||||
merge::{Merge, MergeSorted},
|
||||
Error,
|
||||
};
|
||||
|
||||
/// An artist.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
|
||||
|
@ -1,3 +1,5 @@
|
||||
//! The collection module defines the core data types and their relations.
|
||||
|
||||
pub mod album;
|
||||
pub mod artist;
|
||||
pub mod track;
|
||||
|
@ -1,6 +1,6 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::merge::Merge;
|
||||
use crate::core::collection::merge::Merge;
|
||||
|
||||
/// A single track on an album.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
|
||||
|
@ -3,7 +3,7 @@
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use super::IJsonDatabaseBackend;
|
||||
use crate::core::database::json::IJsonDatabaseBackend;
|
||||
|
||||
/// JSON database backend that uses a local file for persistent storage.
|
||||
pub struct JsonDatabaseFileBackend {
|
||||
|
@ -1,13 +1,14 @@
|
||||
//! Module for storing MusicHoard data in a JSON file database.
|
||||
|
||||
pub mod backend;
|
||||
|
||||
#[cfg(test)]
|
||||
use mockall::automock;
|
||||
|
||||
use crate::Collection;
|
||||
|
||||
use super::{IDatabase, LoadError, SaveError};
|
||||
|
||||
pub mod backend;
|
||||
use crate::core::{
|
||||
collection::Collection,
|
||||
database::{IDatabase, LoadError, SaveError},
|
||||
};
|
||||
|
||||
impl From<serde_json::Error> for LoadError {
|
||||
fn from(err: serde_json::Error) -> LoadError {
|
||||
@ -66,7 +67,13 @@ mod tests {
|
||||
|
||||
use mockall::predicate;
|
||||
|
||||
use crate::{core::testmod::FULL_COLLECTION, Artist, ArtistId, Collection};
|
||||
use crate::core::{
|
||||
collection::{
|
||||
artist::{Artist, ArtistId},
|
||||
Collection,
|
||||
},
|
||||
testmod::FULL_COLLECTION,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
use testmod::DATABASE_JSON;
|
||||
|
@ -1,14 +1,14 @@
|
||||
//! Module for storing MusicHoard data in a database.
|
||||
|
||||
#[cfg(feature = "database-json")]
|
||||
pub mod json;
|
||||
|
||||
use std::fmt;
|
||||
|
||||
#[cfg(test)]
|
||||
use mockall::automock;
|
||||
|
||||
use crate::Collection;
|
||||
|
||||
#[cfg(feature = "database-json")]
|
||||
pub mod json;
|
||||
use crate::core::collection::Collection;
|
||||
|
||||
/// Trait for interacting with the database.
|
||||
#[cfg_attr(test, automock)]
|
||||
|
@ -8,7 +8,7 @@ use std::{
|
||||
str,
|
||||
};
|
||||
|
||||
use super::{Error, IBeetsLibraryExecutor};
|
||||
use crate::core::library::{beets::IBeetsLibraryExecutor, Error};
|
||||
|
||||
const BEET_DEFAULT: &str = "beet";
|
||||
|
||||
|
@ -1,14 +1,15 @@
|
||||
//! Module for interacting with the music library via
|
||||
//! [beets](https://beets.readthedocs.io/en/stable/).
|
||||
|
||||
pub mod executor;
|
||||
|
||||
#[cfg(test)]
|
||||
use mockall::automock;
|
||||
|
||||
use crate::core::collection::track::Format;
|
||||
|
||||
use super::{Error, Field, ILibrary, Item, Query};
|
||||
|
||||
pub mod executor;
|
||||
use crate::core::{
|
||||
collection::track::Format,
|
||||
library::{Error, Field, ILibrary, Item, Query},
|
||||
};
|
||||
|
||||
macro_rules! list_format_separator {
|
||||
() => {
|
||||
@ -176,7 +177,7 @@ mod testmod;
|
||||
mod tests {
|
||||
use mockall::predicate;
|
||||
|
||||
use crate::library::testmod::LIBRARY_ITEMS;
|
||||
use crate::core::library::testmod::LIBRARY_ITEMS;
|
||||
|
||||
use super::*;
|
||||
use testmod::LIBRARY_BEETS;
|
||||
|
@ -1,5 +1,8 @@
|
||||
//! 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)]
|
||||
@ -7,9 +10,6 @@ use mockall::automock;
|
||||
|
||||
use crate::core::collection::track::Format;
|
||||
|
||||
#[cfg(feature = "library-beets")]
|
||||
pub mod beets;
|
||||
|
||||
/// Trait for interacting with the music library.
|
||||
#[cfg_attr(test, automock)]
|
||||
pub trait ILibrary {
|
||||
|
@ -1,6 +1,6 @@
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use crate::{library::Item, Format};
|
||||
use crate::core::{collection::track::Format, library::Item};
|
||||
|
||||
pub static LIBRARY_ITEMS: Lazy<Vec<Item>> = Lazy::new(|| -> Vec<Item> {
|
||||
vec![
|
||||
|
@ -1,4 +1,3 @@
|
||||
// FIXME: visibility?
|
||||
pub mod collection;
|
||||
pub mod database;
|
||||
pub mod library;
|
||||
|
@ -1,12 +1,12 @@
|
||||
//! The core MusicHoard module. Serves as the main entry-point into the library.
|
||||
|
||||
#![allow(clippy::module_inception)]
|
||||
pub mod musichoard;
|
||||
pub mod musichoard_builder;
|
||||
|
||||
use std::fmt::{self, Display};
|
||||
|
||||
use super::collection;
|
||||
use super::database;
|
||||
use super::library;
|
||||
use crate::core::{collection, database, library};
|
||||
|
||||
/// Error type for `musichoard`.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
|
@ -2,15 +2,17 @@ use std::{collections::HashMap, mem};
|
||||
|
||||
use paste::paste;
|
||||
|
||||
use super::collection::{
|
||||
album::{Album, AlbumId},
|
||||
artist::{Artist, ArtistId},
|
||||
track::{Quality, Track, TrackId},
|
||||
Collection, Merge,
|
||||
use crate::core::{
|
||||
collection::{
|
||||
album::{Album, AlbumId},
|
||||
artist::{Artist, ArtistId},
|
||||
track::{Quality, Track, TrackId},
|
||||
Collection, Merge,
|
||||
},
|
||||
database::IDatabase,
|
||||
library::{ILibrary, Item, Query},
|
||||
musichoard::Error,
|
||||
};
|
||||
use super::database::IDatabase;
|
||||
use super::library::{ILibrary, Item, Query};
|
||||
use super::Error;
|
||||
|
||||
/// The Music Hoard. It is responsible for pulling information from both the library and the
|
||||
/// database, ensuring its consistent and writing back any changes.
|
||||
@ -334,13 +336,14 @@ impl<LIB, DB: IDatabase> MusicHoard<LIB, DB> {
|
||||
mod tests {
|
||||
use mockall::predicate;
|
||||
|
||||
use super::*;
|
||||
use crate::core::{
|
||||
collection::artist::{ArtistId, Bandcamp, MusicBrainz, MusicButler, Qobuz},
|
||||
database::{self, MockIDatabase},
|
||||
library::{self, testmod::LIBRARY_ITEMS, MockILibrary},
|
||||
testmod::{FULL_COLLECTION, LIBRARY_COLLECTION},
|
||||
};
|
||||
|
||||
// FIXME: check all crate::* imports - are the tests where they should be?
|
||||
use crate::core::collection::artist::{ArtistId, Bandcamp, MusicBrainz, MusicButler, Qobuz};
|
||||
use crate::core::testmod::{FULL_COLLECTION, LIBRARY_COLLECTION};
|
||||
use crate::database::{self, MockIDatabase};
|
||||
use crate::library::{self, testmod::LIBRARY_ITEMS, MockILibrary};
|
||||
use super::*;
|
||||
|
||||
static MUSICBRAINZ: &str =
|
||||
"https://musicbrainz.org/artist/d368baa8-21ca-4759-9731-0b2753071ad8";
|
||||
|
@ -1,6 +1,8 @@
|
||||
use super::database::IDatabase;
|
||||
use super::library::ILibrary;
|
||||
use super::musichoard::{MusicHoard, NoDatabase, NoLibrary};
|
||||
use crate::core::{
|
||||
database::IDatabase,
|
||||
library::ILibrary,
|
||||
musichoard::musichoard::{MusicHoard, NoDatabase, NoLibrary},
|
||||
};
|
||||
|
||||
/// Builder for [`MusicHoard`]. Its purpose is to make it easier to set various combinations of
|
||||
/// library/database or their absence.
|
||||
@ -51,10 +53,9 @@ impl<LIB, DB> MusicHoardBuilder<LIB, DB> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::core::{database::NullDatabase, library::NullLibrary};
|
||||
|
||||
use crate::database::NullDatabase;
|
||||
use crate::library::NullLibrary;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn no_library_no_database() {
|
||||
|
@ -1,10 +1,10 @@
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use crate::core::collection::{
|
||||
album::{Album, AlbumId},
|
||||
artist::{Artist, ArtistId, ArtistProperties, Bandcamp, MusicBrainz, MusicButler, Qobuz},
|
||||
track::{Format, Quality, Track, TrackId},
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use crate::tests::*;
|
||||
|
||||
pub static LIBRARY_COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| library_collection!());
|
||||
|
14
src/lib.rs
14
src/lib.rs
@ -1,21 +1,11 @@
|
||||
//! MusicHoard - a music collection manager.
|
||||
|
||||
// FIXME: make private and only provide via re-exports.
|
||||
pub mod core;
|
||||
mod core;
|
||||
|
||||
// FIXME: validate the re-exports.
|
||||
pub use core::collection;
|
||||
pub use core::database;
|
||||
pub use core::library;
|
||||
|
||||
// FIXME: validate the re-exports.
|
||||
pub use core::collection::{
|
||||
album::{Album, AlbumId},
|
||||
artist::{Artist, ArtistId, ArtistProperties, Bandcamp, MusicBrainz, MusicButler, Qobuz},
|
||||
track::{Format, Quality, Track, TrackId},
|
||||
Collection,
|
||||
};
|
||||
|
||||
// FIXME: validate the re-exports
|
||||
pub use core::musichoard::{
|
||||
musichoard::{MusicHoard, NoDatabase, NoLibrary},
|
||||
musichoard_builder::MusicHoardBuilder,
|
||||
|
@ -1,3 +1,5 @@
|
||||
mod tui;
|
||||
|
||||
use std::{ffi::OsString, fs::OpenOptions, io, path::PathBuf};
|
||||
|
||||
use ratatui::{backend::CrosstermBackend, Terminal};
|
||||
@ -18,7 +20,6 @@ use musichoard::{
|
||||
MusicHoardBuilder, NoDatabase, NoLibrary,
|
||||
};
|
||||
|
||||
mod tui;
|
||||
use tui::{event::EventChannel, handler::EventHandler, listener::EventListener, ui::Ui, Tui};
|
||||
|
||||
#[derive(StructOpt)]
|
||||
|
@ -2,7 +2,7 @@ use crossterm::event::{KeyEvent, MouseEvent};
|
||||
use std::fmt;
|
||||
use std::sync::mpsc;
|
||||
|
||||
use super::ui::UiError;
|
||||
use crate::tui::ui::UiError;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum EventError {
|
||||
@ -104,7 +104,7 @@ mod tests {
|
||||
|
||||
use crate::tui::ui::UiError;
|
||||
|
||||
use super::{Event, EventChannel, EventError};
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn event_sender() {
|
||||
|
@ -3,7 +3,7 @@ use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||
#[cfg(test)]
|
||||
use mockall::automock;
|
||||
|
||||
use super::{
|
||||
use crate::tui::{
|
||||
event::{Event, EventError, EventReceiver},
|
||||
ui::IUi,
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
use musichoard::{database::IDatabase, library::ILibrary, Collection, MusicHoard};
|
||||
use musichoard::{collection::Collection, database::IDatabase, library::ILibrary, MusicHoard};
|
||||
|
||||
#[cfg(test)]
|
||||
use mockall::automock;
|
||||
|
@ -164,20 +164,17 @@ mod testmod;
|
||||
mod tests {
|
||||
use std::{io, thread};
|
||||
|
||||
use musichoard::Collection;
|
||||
use ratatui::{backend::TestBackend, Terminal};
|
||||
|
||||
use super::testmod::COLLECTION;
|
||||
use musichoard::collection::Collection;
|
||||
|
||||
use super::{
|
||||
event::EventError,
|
||||
handler::MockIEventHandler,
|
||||
lib::MockIMusicHoard,
|
||||
listener::MockIEventListener,
|
||||
ui::{IUi, Ui},
|
||||
Error, Tui,
|
||||
use crate::tui::{
|
||||
handler::MockIEventHandler, lib::MockIMusicHoard, listener::MockIEventListener, ui::Ui,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
use testmod::COLLECTION;
|
||||
|
||||
pub fn terminal() -> Terminal<TestBackend> {
|
||||
let backend = TestBackend::new(150, 30);
|
||||
Terminal::new(backend).unwrap()
|
||||
|
@ -1,6 +1,7 @@
|
||||
use musichoard::{
|
||||
Album, AlbumId, Artist, ArtistId, ArtistProperties, Bandcamp, Format, MusicBrainz, MusicButler,
|
||||
Qobuz, Quality, Track, TrackId,
|
||||
use musichoard::collection::{
|
||||
album::{Album, AlbumId},
|
||||
artist::{Artist, ArtistId, ArtistProperties, Bandcamp, MusicBrainz, MusicButler, Qobuz},
|
||||
track::{Format, Quality, Track, TrackId},
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
|
@ -1,6 +1,11 @@
|
||||
use std::fmt;
|
||||
|
||||
use musichoard::{Album, Artist, Collection, Format, Track};
|
||||
use musichoard::collection::{
|
||||
album::Album,
|
||||
artist::Artist,
|
||||
track::{Format, Track},
|
||||
Collection,
|
||||
};
|
||||
use ratatui::{
|
||||
backend::Backend,
|
||||
layout::{Alignment, Rect},
|
||||
@ -9,7 +14,7 @@ use ratatui::{
|
||||
Frame,
|
||||
};
|
||||
|
||||
use super::{lib::IMusicHoard, Error};
|
||||
use crate::tui::{lib::IMusicHoard, Error};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum UiError {
|
||||
|
@ -1,14 +1,15 @@
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
use musichoard::{
|
||||
collection::artist::Artist,
|
||||
database::{
|
||||
json::{backend::JsonDatabaseFileBackend, JsonDatabase},
|
||||
IDatabase,
|
||||
},
|
||||
Artist,
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
use crate::testlib::COLLECTION;
|
||||
|
||||
|
@ -5,14 +5,14 @@ mod testlib;
|
||||
|
||||
use musichoard::MusicHoard;
|
||||
|
||||
use crate::testlib::COLLECTION;
|
||||
|
||||
#[cfg(feature = "database-json")]
|
||||
use musichoard::database::json::{backend::JsonDatabaseFileBackend, JsonDatabase};
|
||||
|
||||
#[cfg(feature = "library-beets")]
|
||||
use musichoard::library::beets::{executor::BeetsLibraryProcessExecutor, BeetsLibrary};
|
||||
|
||||
use crate::testlib::COLLECTION;
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "database-json")]
|
||||
#[cfg(feature = "library-beets")]
|
||||
|
@ -12,7 +12,7 @@ use musichoard::library::{
|
||||
Field, ILibrary, Item, Query,
|
||||
};
|
||||
|
||||
use super::testmod::LIBRARY_ITEMS;
|
||||
use crate::library::testmod::LIBRARY_ITEMS;
|
||||
|
||||
pub static BEETS_TEST_CONFIG_PATH: Lazy<PathBuf> =
|
||||
Lazy::new(|| fs::canonicalize("./tests/files/library/config.yml").unwrap());
|
||||
|
@ -1,4 +1,4 @@
|
||||
mod testmod;
|
||||
|
||||
#[cfg(feature = "library-beets")]
|
||||
pub mod beets;
|
||||
|
||||
mod testmod;
|
||||
|
@ -1,6 +1,6 @@
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use musichoard::{library::Item, Format};
|
||||
use musichoard::{collection::track::Format, library::Item};
|
||||
|
||||
pub static LIBRARY_ITEMS: Lazy<Vec<Item>> = Lazy::new(|| -> Vec<Item> {
|
||||
vec![
|
||||
|
@ -1,9 +1,12 @@
|
||||
use musichoard::{
|
||||
Album, AlbumId, Artist, ArtistId, ArtistProperties, Bandcamp, Collection, Format, MusicBrainz,
|
||||
MusicButler, Qobuz, Quality, Track, TrackId,
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use musichoard::collection::{
|
||||
album::{Album, AlbumId},
|
||||
artist::{Artist, ArtistId, ArtistProperties, Bandcamp, MusicBrainz, MusicButler, Qobuz},
|
||||
track::{Format, Quality, Track, TrackId},
|
||||
Collection,
|
||||
};
|
||||
|
||||
pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
|
||||
vec![
|
||||
Artist {
|
||||
|
Loading…
Reference in New Issue
Block a user