feat: add --output-format option for json/yaml support in info/status/list modes

Co-authored-by: aider (openai/andrew/openrouter/anthropic/claude-sonnet-4) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-10 11:21:04 -03:00
parent 9f93d6965f
commit 0d1ae9ff12
5 changed files with 353 additions and 3 deletions

View File

@@ -11,6 +11,7 @@ use std::collections::HashMap;
use std::env;
use std::str::FromStr;
use strum::IntoEnumIterator;
use serde::{Deserialize, Serialize};
pub fn get_meta_from_env() -> HashMap<String, String> {
debug!("COMMON: Getting meta from KEEP_META_*");
@@ -162,6 +163,33 @@ pub fn cmd_args_compression_type(cmd: &mut Command, args: &Args) -> CompressionT
compression_type_opt.unwrap()
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum OutputFormat {
Table,
Json,
Yaml,
}
impl FromStr for OutputFormat {
type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"table" => Ok(OutputFormat::Table),
"json" => Ok(OutputFormat::Json),
"yaml" => Ok(OutputFormat::Yaml),
_ => Err(anyhow::anyhow!("Invalid output format. Supported formats: table, json, yaml")),
}
}
}
pub fn get_output_format(args: &Args) -> OutputFormat {
args.options.output_format
.as_ref()
.and_then(|s| OutputFormat::from_str(s).ok())
.unwrap_or(OutputFormat::Table)
}
pub fn cmd_args_meta_plugin_types(cmd: &mut Command, args: &Args) -> Vec<MetaPluginType> {
let mut meta_plugin_types = Vec::new();