From 8ba7dae74935729865c32662c53ca887994701d6 Mon Sep 17 00:00:00 2001 From: Shane Osbourne Date: Sat, 14 Dec 2024 21:20:10 +0000 Subject: [PATCH] support stderr --- .../bsnext_system/src/commands/export_cmd.rs | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/crates/bsnext_system/src/commands/export_cmd.rs b/crates/bsnext_system/src/commands/export_cmd.rs index d496066..0bc29d4 100644 --- a/crates/bsnext_system/src/commands/export_cmd.rs +++ b/crates/bsnext_system/src/commands/export_cmd.rs @@ -28,27 +28,44 @@ pub async fn export_cmd( Ok(SystemStartArgs::InputOnly { input: _ }) => todo!("handle InputOnly"), Ok(SystemStartArgs::PathWithInput { path: _, input }) if input.servers.len() == 1 => { let first = &input.servers[0]; + let write_mode = if args.force { WriteMode::Override } else { WriteMode::Safe }; + let events = export_one_server(cwd, first.clone(), cmd, write_mode).await?; + + let has_error = events + .iter() + .any(|e| matches!(e, ExportEvent::Failed { .. })); + let stdout = &mut std::io::stdout(); + let stderr = &mut std::io::stderr(); + for export_event in &events { - match printer.handle_export_event(stdout, export_event) { - Ok(_) => {} - Err(e) => tracing::error!(?e), - }; + match &export_event { + ExportEvent::Failed { .. } => { + match printer.handle_export_event(stderr, export_event) { + Ok(_) => {} + Err(e) => tracing::error!(?e), + }; + } + _ => { + match printer.handle_export_event(stdout, export_event) { + Ok(_) => {} + Err(e) => tracing::error!(?e), + }; + } + } } - match stdout.flush() { - Ok(_) => {} - Err(e) => tracing::error!("could not flush {e}"), + + match (stderr.flush(), stdout.flush()) { + (Ok(_), Ok(_)) => {} + _ => tracing::error!("could not flush"), }; - if events - .iter() - .any(|e| matches!(e, ExportEvent::Failed { .. })) - { + if has_error { return Err(anyhow::anyhow!("export failed")); } }