use std::process::Output;
use super::{Result, SystemPath, SystemPathBuf};
#[derive(Debug)]
pub struct Command {
executable: String,
arguments: Vec<String>,
current_directory: Option<SystemPathBuf>,
}
impl Command {
pub fn new(executable: impl Into<String>) -> Self {
Self {
executable: executable.into(),
arguments: Vec::new(),
current_directory: None,
}
}
pub fn arg(&mut self, argument: impl Into<String>) -> &mut Self {
self.arguments.push(argument.into());
self
}
pub fn args<I, S>(&mut self, arguments: I) -> &mut Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.arguments.extend(arguments.into_iter().map(Into::into));
self
}
pub fn current_dir(&mut self, directory: impl AsRef<SystemPath>) -> &mut Self {
self.current_directory = Some(directory.as_ref().to_path_buf());
self
}
pub fn get_executable(&self) -> &str {
&self.executable
}
pub fn get_args(&self) -> &[String] {
&self.arguments
}
pub fn get_current_dir(&self) -> Option<&SystemPath> {
self.current_directory.as_deref()
}
}
pub trait CommandExecutor: Send + Sync {
fn execute(&self, command: Command) -> Result<Output>;
fn dyn_clone(&self) -> Box<dyn CommandExecutor>;
}