Shifting code

This commit is contained in:
Wojciech Kozlowski 2023-03-30 23:45:58 +09:00
parent dae9ed791e
commit 9ab00fb1de

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::*;