diff --git a/src/command.rs b/src/command.rs new file mode 100644 index 0000000..acb3c27 --- /dev/null +++ b/src/command.rs @@ -0,0 +1,31 @@ +use crate::logger::Logger; +use std::fmt::{Display, Formatter}; +use std::io; +use std::process::{Command, ExitStatus}; + +pub trait LogRunnable { + fn run(&mut self, logger: &Logger) -> Result<(), ExecutionError>; +} + +impl LogRunnable for Command { + //TODO use specific execution error as error type + fn run(&mut self, logger: &Logger) -> Result<(), ExecutionError> { + todo!("depending on log level, pipe output and only print with logger on error") + } +} + +//TODO show command in specific execution error +#[derive(Debug)] +pub enum ExecutionError { + StartError(io::Error), + BadExitStatus(ExitStatus), +} + +impl Display for ExecutionError { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + ExecutionError::StartError(e) => write!(f, "failed to start command: {}", e), + ExecutionError::BadExitStatus(status) => write!(f, "command failed with exit status: {}", status), + } + } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index b9ec631..e775d74 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ mod file; mod logger; mod os_string_builder; mod server; +mod command; use crate::action::{Action, FileAction, ServerActions}; use crate::file::{FileMatcher, FileNameInfo};