From 1a942b4d234c541e9c3e41150b76c3de0e5b0866 Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Sat, 14 Mar 2026 19:25:53 -0300 Subject: [PATCH] fix: format client --status output as tables instead of raw JSON Change client get_status() to return StatusInfo struct instead of serde_json::Value, then render paths, meta plugins, and compression tables matching the local mode's output style. --- src/client.rs | 11 +++++-- src/modes/client/status.rs | 67 ++++++++++++++++++++++++++++++++++---- 2 files changed, 70 insertions(+), 8 deletions(-) diff --git a/src/client.rs b/src/client.rs index ef3ff79..6173975 100644 --- a/src/client.rs +++ b/src/client.rs @@ -223,8 +223,15 @@ impl KeepClient { Ok(()) } - pub fn get_status(&self) -> Result { - self.get_json("/api/status") + pub fn get_status(&self) -> Result { + #[derive(serde::Deserialize)] + struct ApiResponse { + data: Option, + } + let response: ApiResponse = self.get_json("/api/status")?; + response + .data + .ok_or_else(|| CoreError::Other(anyhow::anyhow!("No status data returned"))) } pub fn get_item_info(&self, id: i64) -> Result { diff --git a/src/modes/client/status.rs b/src/modes/client/status.rs index fa80874..460774a 100644 --- a/src/modes/client/status.rs +++ b/src/modes/client/status.rs @@ -2,6 +2,7 @@ use crate::client::KeepClient; use crate::modes::common::OutputFormat; use crate::modes::common::settings_output_format; use clap::Command; +use comfy_table::{Attribute, Cell, Table}; use log::debug; pub fn mode( @@ -11,21 +12,75 @@ pub fn mode( ) -> Result<(), anyhow::Error> { debug!("CLIENT_STATUS: Getting status from remote server"); - let status = client.get_status()?; + let status_info = client.get_status()?; let output_format = settings_output_format(settings); match output_format { OutputFormat::Json => { - println!("{}", serde_json::to_string_pretty(&status)?); + println!("{}", serde_json::to_string_pretty(&status_info)?); } OutputFormat::Yaml => { - println!("{}", serde_yaml::to_string(&status)?); + println!("{}", serde_yaml::to_string(&status_info)?); } OutputFormat::Table => { - println!("Remote Server Status"); - println!("===================="); - println!("{}", serde_json::to_string_pretty(&status)?); + // Paths + let mut path_table = crate::modes::common::create_table(true); + path_table.set_header(vec![ + Cell::new("Type").add_attribute(Attribute::Bold), + Cell::new("Path").add_attribute(Attribute::Bold), + ]); + path_table.add_row(vec!["Data", &status_info.paths.data]); + path_table.add_row(vec!["Database", &status_info.paths.database]); + println!("PATHS:"); + println!("{path_table}"); + println!(); + + // Configured meta plugins + if let Some(ref configured) = status_info.configured_meta_plugins + && !configured.is_empty() + { + let mut sorted = configured.clone(); + sorted.sort_by(|a, b| a.name.cmp(&b.name)); + + let mut table = crate::modes::common::create_table(true); + table.set_header(vec![ + Cell::new("Plugin Name").add_attribute(Attribute::Bold), + Cell::new("Enabled").add_attribute(Attribute::Bold), + ]); + for plugin in &sorted { + let enabled = status_info.enabled_meta_plugins.contains(&plugin.name); + table.add_row(vec![ + plugin.name.clone(), + if enabled { "Yes" } else { "No" }.to_string(), + ]); + } + println!("META PLUGINS:"); + println!("{table}"); + println!(); + } + + // Compression + if !status_info.compression.is_empty() { + let mut table = crate::modes::common::create_table(true); + table.set_header(vec![ + Cell::new("Type").add_attribute(Attribute::Bold), + Cell::new("Found").add_attribute(Attribute::Bold), + Cell::new("Default").add_attribute(Attribute::Bold), + Cell::new("Binary").add_attribute(Attribute::Bold), + ]); + for comp in &status_info.compression { + table.add_row(vec![ + comp.compression_type.clone(), + if comp.found { "Yes" } else { "No" }.to_string(), + if comp.default { "Yes" } else { "No" }.to_string(), + comp.binary.clone(), + ]); + } + println!("COMPRESSION:"); + println!("{table}"); + println!(); + } } }