refactor: move generate_status_info to common module and update imports
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
1
src/common/mod.rs
Normal file
1
src/common/mod.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pub mod status;
|
||||||
132
src/common/status.rs
Normal file
132
src/common/status.rs
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
|
use strum::IntoEnumIterator;
|
||||||
|
|
||||||
|
use crate::compression_engine;
|
||||||
|
use crate::compression_engine::COMPRESSION_PROGRAMS;
|
||||||
|
use crate::compression_engine::CompressionType;
|
||||||
|
use crate::compression_engine::program::CompressionEngineProgram;
|
||||||
|
use crate::meta_plugin::MetaPluginType;
|
||||||
|
use crate::meta_plugin;
|
||||||
|
|
||||||
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
|
pub struct StatusInfo {
|
||||||
|
pub paths: PathInfo,
|
||||||
|
pub compression: Vec<CompressionInfo>,
|
||||||
|
pub meta_plugins: Vec<MetaPluginInfo>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
|
pub struct PathInfo {
|
||||||
|
pub data: String,
|
||||||
|
pub database: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
|
pub struct CompressionInfo {
|
||||||
|
#[serde(rename = "type")]
|
||||||
|
pub compression_type: String,
|
||||||
|
pub found: bool,
|
||||||
|
pub default: bool,
|
||||||
|
pub binary: String,
|
||||||
|
pub compress: String,
|
||||||
|
pub decompress: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
|
pub struct MetaPluginInfo {
|
||||||
|
pub meta_name: String,
|
||||||
|
pub found: bool,
|
||||||
|
pub enabled: bool,
|
||||||
|
pub binary: String,
|
||||||
|
pub args: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn generate_status_info(
|
||||||
|
data_path: PathBuf,
|
||||||
|
db_path: PathBuf,
|
||||||
|
enabled_meta_plugins: &Vec<MetaPluginType>,
|
||||||
|
) -> StatusInfo {
|
||||||
|
let path_info = PathInfo {
|
||||||
|
data: data_path.into_os_string().into_string().expect("Unable to convert data path to string"),
|
||||||
|
database: db_path.into_os_string().into_string().expect("Unable to convert DB path to string"),
|
||||||
|
};
|
||||||
|
|
||||||
|
let default_type = compression_engine::default_compression_type();
|
||||||
|
let mut compression_info = Vec::new();
|
||||||
|
|
||||||
|
// Sort compression types by their string representation
|
||||||
|
let mut sorted_compression_types: Vec<CompressionType> = CompressionType::iter().collect();
|
||||||
|
sorted_compression_types.sort_by_key(|ct| ct.to_string());
|
||||||
|
|
||||||
|
for compression_type in sorted_compression_types {
|
||||||
|
let compression_program: CompressionEngineProgram =
|
||||||
|
match &COMPRESSION_PROGRAMS[compression_type.clone()] {
|
||||||
|
Some(compression_program) => compression_program.clone(),
|
||||||
|
None => CompressionEngineProgram {
|
||||||
|
program: "".to_string(),
|
||||||
|
compress: Vec::new(),
|
||||||
|
decompress: Vec::new(),
|
||||||
|
supported: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
let is_default = compression_type == default_type;
|
||||||
|
let binary = if compression_program.program.is_empty() {
|
||||||
|
"<INTERNAL>".to_string()
|
||||||
|
} else {
|
||||||
|
compression_program.program
|
||||||
|
};
|
||||||
|
|
||||||
|
compression_info.push(CompressionInfo {
|
||||||
|
compression_type: compression_type.to_string(),
|
||||||
|
found: compression_program.supported,
|
||||||
|
default: is_default,
|
||||||
|
binary,
|
||||||
|
compress: compression_program.compress.join(" "),
|
||||||
|
decompress: compression_program.decompress.join(" "),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut meta_plugin_info = Vec::new();
|
||||||
|
|
||||||
|
// Sort meta plugin types by their meta name
|
||||||
|
let mut sorted_meta_plugins: Vec<MetaPluginType> = MetaPluginType::iter().collect();
|
||||||
|
sorted_meta_plugins.sort_by_key(|meta_plugin_type| {
|
||||||
|
let mut meta_plugin = meta_plugin::get_meta_plugin(meta_plugin_type.clone());
|
||||||
|
meta_plugin.meta_name()
|
||||||
|
});
|
||||||
|
|
||||||
|
for meta_plugin_type in sorted_meta_plugins {
|
||||||
|
let mut meta_plugin = meta_plugin::get_meta_plugin(meta_plugin_type.clone());
|
||||||
|
let is_supported = meta_plugin.is_supported();
|
||||||
|
let is_enabled = enabled_meta_plugins.contains(&meta_plugin_type);
|
||||||
|
|
||||||
|
let (binary_display, args_display) = if !is_supported {
|
||||||
|
("<NOT FOUND>".to_string(), "".to_string())
|
||||||
|
} else {
|
||||||
|
if meta_plugin.is_internal() {
|
||||||
|
("<INTERNAL>".to_string(), "".to_string())
|
||||||
|
} else {
|
||||||
|
if let Some((program, args)) = meta_plugin.program_info() {
|
||||||
|
(program.to_string(), args.join(" "))
|
||||||
|
} else {
|
||||||
|
("<NOT FOUND>".to_string(), "".to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
meta_plugin_info.push(MetaPluginInfo {
|
||||||
|
meta_name: meta_plugin.meta_name(),
|
||||||
|
found: is_supported,
|
||||||
|
enabled: is_enabled,
|
||||||
|
binary: binary_display,
|
||||||
|
args: args_display,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
StatusInfo {
|
||||||
|
paths: path_info,
|
||||||
|
compression: compression_info,
|
||||||
|
meta_plugins: meta_plugin_info,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ use log::warn;
|
|||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
use crate::modes::server::common::{AppState, ApiResponse, check_auth};
|
use crate::modes::server::common::{AppState, ApiResponse, check_auth};
|
||||||
use crate::modes::status::{generate_status_info, StatusInfo};
|
use crate::common::status::{generate_status_info, StatusInfo};
|
||||||
use crate::meta_plugin::MetaPluginType;
|
use crate::meta_plugin::MetaPluginType;
|
||||||
|
|
||||||
pub async fn handle_status(
|
pub async fn handle_status(
|
||||||
|
|||||||
@@ -1,147 +1,17 @@
|
|||||||
use clap::*;
|
use clap::*;
|
||||||
use is_terminal::IsTerminal;
|
use is_terminal::IsTerminal;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use strum::IntoEnumIterator;
|
|
||||||
|
|
||||||
use crate::compression_engine;
|
|
||||||
use crate::compression_engine::COMPRESSION_PROGRAMS;
|
|
||||||
use crate::compression_engine::CompressionType;
|
|
||||||
use crate::compression_engine::program::CompressionEngineProgram;
|
|
||||||
|
|
||||||
use crate::modes::common::{get_format_box_chars_no_border_line_separator, get_output_format, OutputFormat};
|
use crate::modes::common::{get_format_box_chars_no_border_line_separator, get_output_format, OutputFormat};
|
||||||
use prettytable::color;
|
use prettytable::color;
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use serde_yaml;
|
use serde_yaml;
|
||||||
use prettytable::row;
|
use prettytable::row;
|
||||||
use prettytable::{Attr, Cell, Row, Table};
|
use prettytable::{Attr, Cell, Row, Table};
|
||||||
use prettytable::format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR;
|
use prettytable::format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR;
|
||||||
|
|
||||||
use crate::meta_plugin;
|
|
||||||
use crate::meta_plugin::MetaPluginType;
|
use crate::meta_plugin::MetaPluginType;
|
||||||
|
use crate::common::status::{generate_status_info, StatusInfo, PathInfo, CompressionInfo, MetaPluginInfo};
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct StatusInfo {
|
|
||||||
pub paths: PathInfo,
|
|
||||||
pub compression: Vec<CompressionInfo>,
|
|
||||||
pub meta_plugins: Vec<MetaPluginInfo>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct PathInfo {
|
|
||||||
pub data: String,
|
|
||||||
pub database: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct CompressionInfo {
|
|
||||||
#[serde(rename = "type")]
|
|
||||||
pub compression_type: String,
|
|
||||||
pub found: bool,
|
|
||||||
pub default: bool,
|
|
||||||
pub binary: String,
|
|
||||||
pub compress: String,
|
|
||||||
pub decompress: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct MetaPluginInfo {
|
|
||||||
pub meta_name: String,
|
|
||||||
pub found: bool,
|
|
||||||
pub enabled: bool,
|
|
||||||
pub binary: String,
|
|
||||||
pub args: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn generate_status_info(
|
|
||||||
data_path: PathBuf,
|
|
||||||
db_path: PathBuf,
|
|
||||||
enabled_meta_plugins: &Vec<MetaPluginType>,
|
|
||||||
) -> StatusInfo {
|
|
||||||
let path_info = PathInfo {
|
|
||||||
data: data_path.into_os_string().into_string().expect("Unable to convert data path to string"),
|
|
||||||
database: db_path.into_os_string().into_string().expect("Unable to convert DB path to string"),
|
|
||||||
};
|
|
||||||
|
|
||||||
let default_type = compression_engine::default_compression_type();
|
|
||||||
let mut compression_info = Vec::new();
|
|
||||||
|
|
||||||
// Sort compression types by their string representation
|
|
||||||
let mut sorted_compression_types: Vec<CompressionType> = CompressionType::iter().collect();
|
|
||||||
sorted_compression_types.sort_by_key(|ct| ct.to_string());
|
|
||||||
|
|
||||||
for compression_type in sorted_compression_types {
|
|
||||||
let compression_program: CompressionEngineProgram =
|
|
||||||
match &COMPRESSION_PROGRAMS[compression_type.clone()] {
|
|
||||||
Some(compression_program) => compression_program.clone(),
|
|
||||||
None => CompressionEngineProgram {
|
|
||||||
program: "".to_string(),
|
|
||||||
compress: Vec::new(),
|
|
||||||
decompress: Vec::new(),
|
|
||||||
supported: true,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
let is_default = compression_type == default_type;
|
|
||||||
let binary = if compression_program.program.is_empty() {
|
|
||||||
"<INTERNAL>".to_string()
|
|
||||||
} else {
|
|
||||||
compression_program.program
|
|
||||||
};
|
|
||||||
|
|
||||||
compression_info.push(CompressionInfo {
|
|
||||||
compression_type: compression_type.to_string(),
|
|
||||||
found: compression_program.supported,
|
|
||||||
default: is_default,
|
|
||||||
binary,
|
|
||||||
compress: compression_program.compress.join(" "),
|
|
||||||
decompress: compression_program.decompress.join(" "),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut meta_plugin_info = Vec::new();
|
|
||||||
|
|
||||||
// Sort meta plugin types by their meta name
|
|
||||||
let mut sorted_meta_plugins: Vec<MetaPluginType> = MetaPluginType::iter().collect();
|
|
||||||
sorted_meta_plugins.sort_by_key(|meta_plugin_type| {
|
|
||||||
let mut meta_plugin = meta_plugin::get_meta_plugin(meta_plugin_type.clone());
|
|
||||||
meta_plugin.meta_name()
|
|
||||||
});
|
|
||||||
|
|
||||||
for meta_plugin_type in sorted_meta_plugins {
|
|
||||||
let mut meta_plugin = meta_plugin::get_meta_plugin(meta_plugin_type.clone());
|
|
||||||
let is_supported = meta_plugin.is_supported();
|
|
||||||
let is_enabled = enabled_meta_plugins.contains(&meta_plugin_type);
|
|
||||||
|
|
||||||
let (binary_display, args_display) = if !is_supported {
|
|
||||||
("<NOT FOUND>".to_string(), "".to_string())
|
|
||||||
} else {
|
|
||||||
if meta_plugin.is_internal() {
|
|
||||||
("<INTERNAL>".to_string(), "".to_string())
|
|
||||||
} else {
|
|
||||||
if let Some((program, args)) = meta_plugin.program_info() {
|
|
||||||
(program.to_string(), args.join(" "))
|
|
||||||
} else {
|
|
||||||
("<NOT FOUND>".to_string(), "".to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
meta_plugin_info.push(MetaPluginInfo {
|
|
||||||
meta_name: meta_plugin.meta_name(),
|
|
||||||
found: is_supported,
|
|
||||||
enabled: is_enabled,
|
|
||||||
binary: binary_display,
|
|
||||||
args: args_display,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
StatusInfo {
|
|
||||||
paths: path_info,
|
|
||||||
compression: compression_info,
|
|
||||||
meta_plugins: meta_plugin_info,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn build_path_table(path_info: &PathInfo) -> Table {
|
fn build_path_table(path_info: &PathInfo) -> Table {
|
||||||
let mut path_table = Table::new();
|
let mut path_table = Table::new();
|
||||||
|
|||||||
Reference in New Issue
Block a user