From 2433063e702a554d54306e659911b2baf842524a Mon Sep 17 00:00:00 2001 From: SlaVKsVolks Date: Wed, 13 May 2026 14:07:29 -0300 Subject: [PATCH] fix: make export pretty flag explicit --- src/cortex-cli/src/export_cmd.rs | 40 ++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/cortex-cli/src/export_cmd.rs b/src/cortex-cli/src/export_cmd.rs index 39f3369b0..0c93eb961 100644 --- a/src/cortex-cli/src/export_cmd.rs +++ b/src/cortex-cli/src/export_cmd.rs @@ -39,8 +39,8 @@ pub struct ExportCommand { #[arg(short, long, value_enum, default_value_t = ExportFormat::Json)] pub format: ExportFormat, - /// Pretty-print the output (for json/yaml) - #[arg(long, default_value_t = true)] + /// Pretty-print JSON output + #[arg(long, action = clap::ArgAction::SetTrue)] pub pretty: bool, } @@ -111,6 +111,8 @@ pub struct ExportToolCall { impl ExportCommand { /// Run the export command. pub async fn run(self) -> Result<()> { + validate_format_options(self.format, self.pretty)?; + let cortex_home = dirs::home_dir() .map(|h| h.join(".cortex")) .ok_or_else(|| anyhow::anyhow!("Could not determine home directory"))?; @@ -241,6 +243,14 @@ impl ExportCommand { } } +fn validate_format_options(format: ExportFormat, pretty: bool) -> Result<()> { + if pretty && format != ExportFormat::Json { + bail!("--pretty is only supported for JSON exports"); + } + + Ok(()) +} + /// Escape a field for CSV output. fn escape_csv_field(field: &str) -> String { if field.contains(',') || field.contains('"') || field.contains('\n') { @@ -466,4 +476,30 @@ mod tests { assert_eq!(refs.len(), 1); assert!(refs.contains(&"explore".to_string())); } + + #[test] + fn test_pretty_defaults_to_false() { + let cmd = ExportCommand::try_parse_from(["export", "session-id"]).unwrap(); + + assert!(!cmd.pretty); + } + + #[test] + fn test_validate_format_options_allows_pretty_json() { + validate_format_options(ExportFormat::Json, true).unwrap(); + } + + #[test] + fn test_validate_format_options_rejects_pretty_yaml() { + let err = validate_format_options(ExportFormat::Yaml, true).unwrap_err(); + + assert!(err.to_string().contains("JSON exports")); + } + + #[test] + fn test_validate_format_options_rejects_pretty_csv() { + let err = validate_format_options(ExportFormat::Csv, true).unwrap_err(); + + assert!(err.to_string().contains("JSON exports")); + } }