ocy_core/
command.rs

1use std::{process::Command, thread::sleep, time::Duration};
2
3use crate::models::FileInfo;
4
5use eyre::{Context, Result};
6
7pub trait CommandExecutor {
8    fn execute_command(&self, work_dir: &FileInfo, command: &str) -> Result<()>;
9}
10
11pub struct MockCommandExecutor;
12
13impl CommandExecutor for MockCommandExecutor {
14    fn execute_command(&self, _work_dir: &FileInfo, _command: &str) -> Result<()> {
15        sleep(Duration::from_secs(2));
16        Ok(())
17    }
18}
19
20pub struct RealCommandExecutor;
21
22impl CommandExecutor for RealCommandExecutor {
23    fn execute_command(&self, work_dir: &FileInfo, command: &str) -> Result<()> {
24        let mut iter = command.split_ascii_whitespace();
25        let cmd = iter.next().unwrap();
26
27        Command::new(cmd)
28            .current_dir(&work_dir.path)
29            .args(iter)
30            .status()
31            .context("Failed to execute command")?;
32        Ok(())
33    }
34}