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.
This commit is contained in:
@@ -223,8 +223,15 @@ impl KeepClient {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_status(&self) -> Result<serde_json::Value, CoreError> {
|
||||
self.get_json("/api/status")
|
||||
pub fn get_status(&self) -> Result<crate::common::status::StatusInfo, CoreError> {
|
||||
#[derive(serde::Deserialize)]
|
||||
struct ApiResponse {
|
||||
data: Option<crate::common::status::StatusInfo>,
|
||||
}
|
||||
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<ItemInfo, CoreError> {
|
||||
|
||||
@@ -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!();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user