1use clap::Args;
5use handlebars::Handlebars;
6use handlebars::JsonValue;
7use std::error::Error;
8
9#[cfg(feature = "device")]
10pub mod device;
11#[cfg(feature = "ip")]
12pub mod ip;
13#[cfg(feature = "mail")]
14pub mod mail;
15#[cfg(feature = "mpris")]
16pub mod mpris;
17#[cfg(feature = "network")]
18pub mod network;
19#[cfg(feature = "razor")]
20pub mod razor;
21#[cfg(feature = "weather")]
22pub mod weather;
23#[cfg(feature = "wireguard")]
24pub mod wireguard;
25
26#[derive(Args)]
27pub struct PrintFormattingStringsArgs {
29 pub command: String,
30 pub selector: Option<device::SystemStats>,
31}
32
33pub struct RubbleResult {
35 pub json_value: Result<JsonValue, Box<dyn Error>>,
36 pub default_format: &'static str,
37 pub user_format: Option<String>,
38}
39
40impl RubbleResult {
41 pub fn new(
44 json_value: Result<JsonValue, Box<dyn Error>>,
45 default_format: &'static str,
46 ) -> Self {
47 Self {
48 json_value: json_value,
49 default_format: default_format,
50 user_format: None,
51 }
52 }
53
54 pub fn print(&self) {
57 let reg = Handlebars::new();
58 let fmt = if self.user_format.is_some() {
60 self.user_format.as_ref().unwrap()
61 } else {
62 self.default_format
63 };
64 let render = reg.render_template(fmt, &self.json_value.as_ref().unwrap());
65 println!("{}", render.unwrap())
66 }
67}
68
69pub fn format_formatting_strings(options: &str) -> String {
79 options
80 .split_whitespace()
81 .into_iter()
82 .map(|o| format!("{}{}{} ", "{{", o, "}}"))
83 .collect()
84}
85
86macro_rules! avaliable_formattings {
89 (
90 $default_format:expr,
91 $formatting_strings:expr
92 ) => {
93 pub fn default_format() -> &'static str {
94 ($default_format)
95 }
96 pub fn formatting_strings() -> &'static str {
97 ($formatting_strings)
98 }
99 };
100}
101
102pub(crate) use avaliable_formattings;