Rename SystemExecutor to CommandExecutor
This commit is contained in:
parent
68d5fa69d4
commit
a0d38454ca
@ -53,13 +53,13 @@ impl DatabaseWrite for JsonDatabase {
|
||||
|
||||
impl Database for JsonDatabase {}
|
||||
|
||||
/// JSON database that uses a local file for persistent storage.
|
||||
/// JSON database backend that uses a local file for persistent storage.
|
||||
pub struct JsonDatabaseFileBackend {
|
||||
path: PathBuf,
|
||||
}
|
||||
|
||||
impl JsonDatabaseFileBackend {
|
||||
/// Create a database instance that will read/write to the provided path.
|
||||
/// Create a [JsonDatabaseFileBackend] that will read/write to the provided path.
|
||||
pub fn new(path: &Path) -> Self {
|
||||
JsonDatabaseFileBackend {
|
||||
path: path.to_path_buf(),
|
||||
|
@ -89,7 +89,7 @@ pub trait BeetsLibraryExecutor {
|
||||
fn exec(&mut self, arguments: &[String]) -> Result<Vec<String>, Error>;
|
||||
}
|
||||
|
||||
/// Struct for interacting with the music library via beets.
|
||||
/// Beets library.
|
||||
pub struct BeetsLibrary {
|
||||
executor: Box<dyn BeetsLibraryExecutor + Send>,
|
||||
}
|
||||
@ -106,7 +106,7 @@ trait LibraryPrivate {
|
||||
}
|
||||
|
||||
impl BeetsLibrary {
|
||||
/// Create a new beets library with the provided executor, e.g. [BeetsLibrarySystemExecutor].
|
||||
/// Create a new beets library with the provided executor, e.g. [BeetsLibraryCommandExecutor].
|
||||
pub fn new(executor: Box<dyn BeetsLibraryExecutor + Send>) -> BeetsLibrary {
|
||||
BeetsLibrary { executor }
|
||||
}
|
||||
@ -236,42 +236,42 @@ impl LibraryPrivate for BeetsLibrary {
|
||||
}
|
||||
}
|
||||
|
||||
/// Executor for executing beets commands on the local system.
|
||||
/// Beets library executor that executes beets commands in their own process.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The beets executable is not safe to call concurrently for operations on the same
|
||||
/// database/library. Therefore, all functions that create a [SystemExecutor] or modify which
|
||||
/// library it works with are marked unsafe. It is the caller's responsibility to make sure the
|
||||
/// library is not being concurrently accessed from anywhere else.
|
||||
pub struct BeetsLibrarySystemExecutor {
|
||||
/// database/library. Therefore, all functions that create a [BeetsLibraryCommandExecutor] or modify
|
||||
/// which library it works with are marked unsafe. It is the caller's responsibility to make sure
|
||||
/// the library is not being concurrently accessed from anywhere else.
|
||||
pub struct BeetsLibraryCommandExecutor {
|
||||
bin: String,
|
||||
config: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl BeetsLibrarySystemExecutor {
|
||||
/// Create a new [SystemExecutor] that uses the provided beets executable.
|
||||
impl BeetsLibraryCommandExecutor {
|
||||
/// Create a new [BeetsLibraryCommandExecutor] that uses the provided beets executable.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The caller must ensure the library is not being concurrently accessed from anywhere else.
|
||||
pub unsafe fn new(bin: &str) -> Self {
|
||||
BeetsLibrarySystemExecutor {
|
||||
BeetsLibraryCommandExecutor {
|
||||
bin: bin.to_string(),
|
||||
config: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new [SystemExecutor] that uses the system's default beets executable.
|
||||
/// Create a new [BeetsLibraryCommandExecutor] that uses the system's default beets executable.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The caller must ensure the library is not being concurrently accessed from anywhere else.
|
||||
pub unsafe fn default() -> Self {
|
||||
BeetsLibrarySystemExecutor::new("beet")
|
||||
BeetsLibraryCommandExecutor::new("beet")
|
||||
}
|
||||
|
||||
/// Update the configuration file for the beets executable.
|
||||
/// Update the configuration file passed to the beets executable.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
@ -282,7 +282,7 @@ impl BeetsLibrarySystemExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
impl BeetsLibraryExecutor for BeetsLibrarySystemExecutor {
|
||||
impl BeetsLibraryExecutor for BeetsLibraryCommandExecutor {
|
||||
fn exec(&mut self, arguments: &[String]) -> Result<Vec<String>, Error> {
|
||||
let mut cmd = Command::new(&self.bin);
|
||||
if let Some(ref path) = self.config {
|
||||
|
@ -8,7 +8,7 @@ use musichoard::{
|
||||
DatabaseWrite,
|
||||
},
|
||||
library::{
|
||||
beets::{BeetsLibrary, BeetsLibrarySystemExecutor},
|
||||
beets::{BeetsLibrary, BeetsLibraryCommandExecutor},
|
||||
Library, Query,
|
||||
},
|
||||
};
|
||||
@ -37,7 +37,7 @@ fn main() {
|
||||
let opt = Opt::from_args();
|
||||
|
||||
let mut beets = BeetsLibrary::new(Box::new(unsafe {
|
||||
BeetsLibrarySystemExecutor::default().config(opt.beets_config_file_path.as_deref())
|
||||
BeetsLibraryCommandExecutor::default().config(opt.beets_config_file_path.as_deref())
|
||||
}));
|
||||
|
||||
let collection = beets
|
||||
|
@ -7,7 +7,7 @@ use once_cell::sync::Lazy;
|
||||
|
||||
use musichoard::{
|
||||
library::{
|
||||
beets::{BeetsLibrary, BeetsLibrarySystemExecutor},
|
||||
beets::{BeetsLibrary, BeetsLibraryCommandExecutor},
|
||||
Library, Query, QueryOption,
|
||||
},
|
||||
Artist,
|
||||
@ -17,13 +17,13 @@ use crate::COLLECTION;
|
||||
|
||||
static BEETS_EMPTY_CONFIG: Lazy<Arc<Mutex<BeetsLibrary>>> = Lazy::new(|| {
|
||||
Arc::new(Mutex::new(BeetsLibrary::new(Box::new(unsafe {
|
||||
BeetsLibrarySystemExecutor::default()
|
||||
BeetsLibraryCommandExecutor::default()
|
||||
}))))
|
||||
});
|
||||
|
||||
static BEETS_TEST_CONFIG: Lazy<Arc<Mutex<BeetsLibrary>>> = Lazy::new(|| {
|
||||
Arc::new(Mutex::new(BeetsLibrary::new(Box::new(unsafe {
|
||||
BeetsLibrarySystemExecutor::default().config(Some(
|
||||
BeetsLibraryCommandExecutor::default().config(Some(
|
||||
&fs::canonicalize("./tests/files/library/config.yml").unwrap(),
|
||||
))
|
||||
}))))
|
||||
|
Loading…
Reference in New Issue
Block a user