use serde::{Deserialize, Serialize};
use schemars::JsonSchema;
#[derive(Debug, Deserialize, JsonSchema)]
pub struct Input {
#[serde(default = "default_path")]
pub path: String,
}
fn default_path() -> String {
"/".to_string()
}
#[derive(Debug, Serialize, JsonSchema)]
pub struct Output {
pub path: String,
pub total: String,
pub used: String,
pub free: String,
pub percent_used: f64,
}
pub struct SysutilDisk;
impl SysutilDisk {
pub const MODULE_ID: &'static str = "sysutil.disk";
pub const DESCRIPTION: &'static str =
"Get disk usage statistics for a given filesystem path";
pub fn execute(input: Input) -> Output {
Output {
path: input.path.clone(),
total: "N/A (not implemented)".to_string(),
used: "N/A".to_string(),
free: "N/A".to_string(),
percent_used: 0.0,
}
}
}
fn format_bytes(mut bytes: u64) -> String {
let units = ["B", "KB", "MB", "GB", "TB", "PB"];
let mut value = bytes as f64;
let mut unit = units[0];
for u in &units[1..] {
if value < 1024.0 {
break;
}
value /= 1024.0;
unit = u;
}
format!("{value:.1} {unit}")
}
fn main() {
let input = Input { path: "/".to_string() };
let output = SysutilDisk::execute(input);
println!("{}", serde_json::to_string_pretty(&output).unwrap());
}