use crate::prelude::*;
#[injectable]
pub(crate) struct SoxFactory {
options: Ref<SoxOptions>,
}
impl SoxFactory {
#[cfg(test)]
pub(crate) fn new(options: Ref<SoxOptions>) -> Self {
Self { options }
}
#[must_use]
pub(crate) fn create(&self) -> CommandInfo {
CommandInfo {
program: self.binary().to_owned(),
args: self.base_args(),
}
}
#[must_use]
pub(crate) fn binary(&self) -> &str {
if let Some(path) = &self.options.sox_path {
path.to_str().expect("sox_path should be valid UTF-8")
} else if self.options.sox_ng {
SOX_NG
} else {
SOX
}
}
fn base_args(&self) -> Vec<String> {
if self.options.sox_ng {
vec!["--single-threaded".to_owned()]
} else {
Vec::new()
}
}
}