Create labadoor-common
and move run_bin()
in it
This commit is contained in:
parent
924224c7fa
commit
0ab168b7f7
5 changed files with 53 additions and 29 deletions
6
labadoor-common/Cargo.toml
Normal file
6
labadoor-common/Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "labadoor-common"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
38
labadoor-common/src/lib.rs
Normal file
38
labadoor-common/src/lib.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
pub type Binary = Vec<String>;
|
||||
pub type BinaryResult = Result<String, String>;
|
||||
|
||||
pub struct OpenBinaryArgs {
|
||||
pub method: String,
|
||||
pub identifier: String,
|
||||
pub resource_shortcut: i8,
|
||||
}
|
||||
|
||||
pub fn run_bin(bin: Binary) -> BinaryResult {
|
||||
use std::{
|
||||
io::Read,
|
||||
process::{Command, Stdio},
|
||||
};
|
||||
|
||||
let mut ret = Err("".to_string());
|
||||
let mut iter = bin.iter();
|
||||
let mut cmd = Command::new(iter.next().unwrap());
|
||||
cmd.args(iter);
|
||||
|
||||
let mut child = cmd.stdout(Stdio::piped()).spawn().unwrap();
|
||||
let mut success = child.wait().unwrap().success();
|
||||
|
||||
let mut s = String::from("");
|
||||
child.stdout.unwrap().read_to_string(&mut s).unwrap();
|
||||
s = String::from(s.trim());
|
||||
|
||||
ret = if success { Ok(s) } else { Err(s) };
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn run_open(args: OpenBinaryArgs, bin: Binary) -> BinaryResult {
|
||||
let mut auth_bin = bin.clone();
|
||||
auth_bin.push(args.method.clone());
|
||||
auth_bin.push(args.identifier.clone());
|
||||
auth_bin.push(args.resource_shortcut.to_string());
|
||||
run_bin(auth_bin)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue