|
|
@ -1,8 +1,8 @@ |
|
|
|
use serde::de::DeserializeOwned; |
|
|
|
use serde::de::DeserializeOwned; |
|
|
|
use serde_json::from_slice; |
|
|
|
use serde_json::{from_slice, Value}; |
|
|
|
use shlex::split; |
|
|
|
use shlex::split; |
|
|
|
use std::process::{Command, Output}; |
|
|
|
use std::process::{Command, Output}; |
|
|
|
use u_lib::{datatypes::DataResult, messaging::AsMsg, utils::VecDisplay}; |
|
|
|
use u_lib::{datatypes::DataResult, utils::VecDisplay}; |
|
|
|
|
|
|
|
|
|
|
|
const PANEL_BINARY: &str = "/u_panel"; |
|
|
|
const PANEL_BINARY: &str = "/u_panel"; |
|
|
|
|
|
|
|
|
|
|
@ -19,8 +19,8 @@ impl Panel { |
|
|
|
.unwrap() |
|
|
|
.unwrap() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn output_argv<T: AsMsg + DeserializeOwned>(args: &[&str]) -> PanelResult<T> { |
|
|
|
pub fn output_argv<T: DeserializeOwned>(argv: &[&str]) -> PanelResult<T> { |
|
|
|
let result = Self::run(args); |
|
|
|
let result = Self::run(argv); |
|
|
|
from_slice(&result.stdout).map_err(|e| { |
|
|
|
from_slice(&result.stdout).map_err(|e| { |
|
|
|
eprintln!( |
|
|
|
eprintln!( |
|
|
|
"Failed to decode panel response: '{}'", |
|
|
|
"Failed to decode panel response: '{}'", |
|
|
@ -30,7 +30,7 @@ impl Panel { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn output<T: AsMsg + DeserializeOwned>(args: impl Into<String>) -> PanelResult<T> { |
|
|
|
pub fn output<T: DeserializeOwned>(args: impl Into<String>) -> PanelResult<T> { |
|
|
|
let splitted = split(args.into().as_ref()).unwrap(); |
|
|
|
let splitted = split(args.into().as_ref()).unwrap(); |
|
|
|
Self::output_argv( |
|
|
|
Self::output_argv( |
|
|
|
splitted |
|
|
|
splitted |
|
|
@ -41,19 +41,19 @@ impl Panel { |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn status_is_ok<T: AsMsg + DeserializeOwned>(data: PanelResult<T>) -> T { |
|
|
|
fn status_is_ok<T: DeserializeOwned>(data: PanelResult<T>) -> T { |
|
|
|
match data.unwrap() { |
|
|
|
match data.unwrap() { |
|
|
|
DataResult::Ok(r) => r, |
|
|
|
DataResult::Ok(r) => r, |
|
|
|
DataResult::Err(e) => panic!("Panel failed: {}", e), |
|
|
|
DataResult::Err(e) => panic!("Panel failed: {}", e), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn check_status<'s, T: AsMsg + DeserializeOwned>(args: &'s str) { |
|
|
|
pub fn check_status(args: impl Into<String>) { |
|
|
|
let result: PanelResult<T> = Self::output(args); |
|
|
|
let result: PanelResult<Value> = Self::output(args); |
|
|
|
Self::status_is_ok(result); |
|
|
|
Self::status_is_ok(result); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn check_output<T: AsMsg + DeserializeOwned>(args: impl Into<String>) -> T { |
|
|
|
pub fn check_output<T: DeserializeOwned>(args: impl Into<String>) -> T { |
|
|
|
let result = Self::output(args); |
|
|
|
let result = Self::output(args); |
|
|
|
Self::status_is_ok(result) |
|
|
|
Self::status_is_ok(result) |
|
|
|
} |
|
|
|
} |
|
|
|