Clean up private helper methods
This commit is contained in:
parent
84b05567de
commit
fdf3687d54
@ -78,15 +78,39 @@ pub struct Beets {
|
||||
executor: Box<dyn BeetsExecutor>,
|
||||
}
|
||||
|
||||
impl Beets {
|
||||
pub fn new(executor: Box<dyn BeetsExecutor>) -> Beets {
|
||||
Beets { executor }
|
||||
}
|
||||
}
|
||||
|
||||
trait LibraryPrivate {
|
||||
const CMD_LIST: &'static str;
|
||||
const SEPARATOR: &'static str;
|
||||
const LIST_FORMAT: &'static str;
|
||||
|
||||
fn list_cmd_and_args(query: &Query) -> Vec<String>;
|
||||
fn list_to_albums(list_output: Vec<String>) -> Result<Vec<Album>, Error>;
|
||||
}
|
||||
|
||||
impl Library for Beets {
|
||||
fn list(&mut self, query: &Query) -> Result<Vec<Album>, Error> {
|
||||
let cmd = Self::list_cmd_and_args(query);
|
||||
let output = self.executor.exec(cmd)?;
|
||||
Self::list_to_albums(output)
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! separator {
|
||||
() => {
|
||||
"-*^-"
|
||||
};
|
||||
}
|
||||
|
||||
impl Beets {
|
||||
const SEPARATOR: &str = separator!();
|
||||
const LIST_FORMAT: &str = concat!(
|
||||
impl LibraryPrivate for Beets {
|
||||
const CMD_LIST: &'static str = "ls";
|
||||
const SEPARATOR: &'static str = separator!();
|
||||
const LIST_FORMAT: &'static str = concat!(
|
||||
"--format=",
|
||||
"$albumartist",
|
||||
separator!(),
|
||||
@ -101,8 +125,11 @@ impl Beets {
|
||||
"$artist"
|
||||
);
|
||||
|
||||
pub fn new(executor: Box<dyn BeetsExecutor>) -> Beets {
|
||||
Beets { executor }
|
||||
fn list_cmd_and_args(query: &Query) -> Vec<String> {
|
||||
let mut cmd: Vec<String> = vec![String::from(Self::CMD_LIST)];
|
||||
cmd.push(Self::LIST_FORMAT.to_string());
|
||||
cmd.append(&mut query.to_args());
|
||||
cmd
|
||||
}
|
||||
|
||||
fn list_to_albums(list_output: Vec<String>) -> Result<Vec<Album>, Error> {
|
||||
@ -147,22 +174,11 @@ impl Beets {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Ok(albums)
|
||||
}
|
||||
}
|
||||
|
||||
impl Library for Beets {
|
||||
fn list(&mut self, query: &Query) -> Result<Vec<Album>, Error> {
|
||||
let mut arguments: Vec<String> = vec![String::from("ls")];
|
||||
arguments.push(Self::LIST_FORMAT.to_string());
|
||||
arguments.append(&mut query.to_args());
|
||||
|
||||
let output = self.executor.exec(arguments)?;
|
||||
|
||||
Self::list_to_albums(output)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SystemExecutor {
|
||||
bin: String,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user