Add command module

This commit is contained in:
Leonard Steppy 2024-12-17 06:19:09 +01:00
parent bdd1652595
commit d0a14d7763
2 changed files with 32 additions and 0 deletions

31
src/command.rs Normal file
View File

@ -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),
}
}
}

View File

@ -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};