Resolve "Local collection trait and beets implementation" #9

Merged
wojtek merged 12 commits from 4---local-collection-trait-and-beets-implementation into main 2023-03-31 14:24:54 +02:00
Showing only changes of commit 9ab00fb1de - Show all commits

View File

@ -78,32 +78,6 @@ pub struct Beets {
executor: Box<dyn BeetsExecutor>, executor: Box<dyn BeetsExecutor>,
} }
pub struct SystemExecutor {
bin: String,
}
impl SystemExecutor {
pub fn new(bin: &str) -> SystemExecutor {
SystemExecutor {
bin: bin.to_string(),
}
}
}
impl Default for SystemExecutor {
fn default() -> Self {
SystemExecutor::new("beet")
}
}
impl BeetsExecutor for SystemExecutor {
fn exec(&mut self, arguments: Vec<String>) -> Result<Vec<String>, Error> {
let output = Command::new(&self.bin).args(arguments).output()?;
let output = std::str::from_utf8(&output.stdout)?;
Ok(output.split('\n').map(|s| s.to_string()).collect())
}
}
#[derive(Debug, Hash, Eq, PartialEq)] #[derive(Debug, Hash, Eq, PartialEq)]
struct AlbumId { struct AlbumId {
artist: String, artist: String,
@ -206,6 +180,32 @@ impl Library for Beets {
} }
} }
pub struct SystemExecutor {
bin: String,
}
impl SystemExecutor {
pub fn new(bin: &str) -> SystemExecutor {
SystemExecutor {
bin: bin.to_string(),
}
}
}
impl Default for SystemExecutor {
fn default() -> Self {
SystemExecutor::new("beet")
}
}
impl BeetsExecutor for SystemExecutor {
fn exec(&mut self, arguments: Vec<String>) -> Result<Vec<String>, Error> {
let output = Command::new(&self.bin).args(arguments).output()?;
let output = std::str::from_utf8(&output.stdout)?;
Ok(output.split('\n').map(|s| s.to_string()).collect())
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;