summaryrefslogtreecommitdiff
path: root/src/client/executor.rs
blob: 5fbba0b9e12196fcffde8720c4bd1ecd5b1e5810 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use crate::executor::tasks::{IntoTask, IntoTaskErr, Task};

pub(crate) mod tasks;

pub(crate) struct Executor<'a> {
    task: &'a Task,
    args: Box<[String]>,
    output: Option<Result<String, String>>,
}

impl<'a> Executor<'a> {
    pub(crate) fn new(task: impl IntoTask, args: String) -> Result<Self, IntoTaskErr> {
        let task = task.into_task()?;
        Ok(Self {
            task: task,
            args: Box::new([args]),
            output: None,
        })
    }

    pub(crate) fn run(&mut self) -> Option<&Result<String, String>> {
        self.output = Some((self.task.exec)(&self.args));
        self.output.as_ref()
    }
}