use clap::Args;
use handlebars::Handlebars;
use handlebars::JsonValue;
use std::error::Error;
#[cfg(feature = "device")]
pub mod device;
#[cfg(feature = "ip")]
pub mod ip;
#[cfg(feature = "mail")]
pub mod mail;
#[cfg(feature = "mpris")]
pub mod mpris;
#[cfg(feature = "network")]
pub mod network;
#[cfg(feature = "razor")]
pub mod razor;
#[cfg(feature = "weather")]
pub mod weather;
#[cfg(feature = "wireguard")]
pub mod wireguard;
#[derive(Args)]
pub struct PrintFormattingStringsArgs {
pub command: String,
pub selector: Option<device::SystemStats>,
}
pub struct RubbleResult {
pub json_value: Result<JsonValue, Box<dyn Error>>,
pub default_format: &'static str,
pub user_format: Option<String>,
}
impl RubbleResult {
pub fn new(
json_value: Result<JsonValue, Box<dyn Error>>,
default_format: &'static str,
) -> Self {
Self {
json_value: json_value,
default_format: default_format,
user_format: None,
}
}
pub fn print(&self) {
let reg = Handlebars::new();
let fmt = if self.user_format.is_some() {
self.user_format.as_ref().unwrap()
} else {
self.default_format
};
let render = reg.render_template(fmt, &self.json_value.as_ref().unwrap());
println!("{}", render.unwrap())
}
}
pub fn format_formatting_strings(options: &str) -> String {
options
.split_whitespace()
.into_iter()
.map(|o| format!("{}{}{} ", "{{", o, "}}"))
.collect()
}
macro_rules! avaliable_formattings {
(
$default_format:expr,
$formatting_strings:expr
) => {
pub fn default_format() -> &'static str {
($default_format)
}
pub fn formatting_strings() -> &'static str {
($formatting_strings)
}
};
}
pub(crate) use avaliable_formattings;