@@ -39,8 +39,8 @@ pub struct ExportCommand {
3939 #[ arg( short, long, value_enum, default_value_t = ExportFormat :: Json ) ]
4040 pub format : ExportFormat ,
4141
42- /// Pretty-print the output (for json/yaml)
43- #[ arg( long, default_value_t = true ) ]
42+ /// Pretty-print JSON output
43+ #[ arg( long, action = clap :: ArgAction :: SetTrue ) ]
4444 pub pretty : bool ,
4545}
4646
@@ -111,6 +111,8 @@ pub struct ExportToolCall {
111111impl ExportCommand {
112112 /// Run the export command.
113113 pub async fn run ( self ) -> Result < ( ) > {
114+ validate_format_options ( self . format , self . pretty ) ?;
115+
114116 let cortex_home = dirs:: home_dir ( )
115117 . map ( |h| h. join ( ".cortex" ) )
116118 . ok_or_else ( || anyhow:: anyhow!( "Could not determine home directory" ) ) ?;
@@ -241,6 +243,14 @@ impl ExportCommand {
241243 }
242244}
243245
246+ fn validate_format_options ( format : ExportFormat , pretty : bool ) -> Result < ( ) > {
247+ if pretty && format != ExportFormat :: Json {
248+ bail ! ( "--pretty is only supported for JSON exports" ) ;
249+ }
250+
251+ Ok ( ( ) )
252+ }
253+
244254/// Escape a field for CSV output.
245255fn escape_csv_field ( field : & str ) -> String {
246256 if field. contains ( ',' ) || field. contains ( '"' ) || field. contains ( '\n' ) {
@@ -466,4 +476,30 @@ mod tests {
466476 assert_eq ! ( refs. len( ) , 1 ) ;
467477 assert ! ( refs. contains( & "explore" . to_string( ) ) ) ;
468478 }
479+
480+ #[ test]
481+ fn test_pretty_defaults_to_false ( ) {
482+ let cmd = ExportCommand :: try_parse_from ( [ "export" , "session-id" ] ) . unwrap ( ) ;
483+
484+ assert ! ( !cmd. pretty) ;
485+ }
486+
487+ #[ test]
488+ fn test_validate_format_options_allows_pretty_json ( ) {
489+ validate_format_options ( ExportFormat :: Json , true ) . unwrap ( ) ;
490+ }
491+
492+ #[ test]
493+ fn test_validate_format_options_rejects_pretty_yaml ( ) {
494+ let err = validate_format_options ( ExportFormat :: Yaml , true ) . unwrap_err ( ) ;
495+
496+ assert ! ( err. to_string( ) . contains( "JSON exports" ) ) ;
497+ }
498+
499+ #[ test]
500+ fn test_validate_format_options_rejects_pretty_csv ( ) {
501+ let err = validate_format_options ( ExportFormat :: Csv , true ) . unwrap_err ( ) ;
502+
503+ assert ! ( err. to_string( ) . contains( "JSON exports" ) ) ;
504+ }
469505}
0 commit comments