You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.1 KiB
55 lines
1.1 KiB
use std::process::{ |
|
Command, |
|
Output |
|
}; |
|
|
|
pub type JobResult<'res> = Result<&'res [u8], &'res [u8]>; |
|
|
|
pub trait Job { |
|
async fn run(&mut self); |
|
fn result(&self) -> JobResult; |
|
} |
|
|
|
pub struct ShellJob<'cmd> { |
|
pub result: JobResult<'cmd>, |
|
pub cmd: &'cmd str, |
|
pub args: Vec<&'cmd str> |
|
} |
|
|
|
impl ShellJob { |
|
pub fn from_raw(raw_cmd: &str) -> Self { |
|
let cmd_parts = raw_cmd.split(" "); |
|
Self { |
|
cmd: cmd_parts[0], |
|
args: cmd_parts[1..], |
|
result: Err("Did not run".as_bytes()) |
|
} |
|
} |
|
} |
|
|
|
impl Job for ShellJob { |
|
async fn run(&mut self) { |
|
let result = Command::new(self.cmd) |
|
.args(&self.args) |
|
.output(); |
|
self.result = match result { |
|
Ok(output) => { |
|
if output.status != 0 { |
|
Err(&output.stderr) |
|
} else { |
|
Ok(&output.stdout) |
|
} |
|
} |
|
Err(e) => e.to_string().as_bytes() |
|
} |
|
} |
|
|
|
fn result(&self) -> JobResult { |
|
self.result |
|
} |
|
} |
|
|
|
/* |
|
pub struct PyJob { |
|
|
|
}*/ |