Skip to content

Commit

Permalink
fix: return valid json
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Aug 29, 2024
1 parent 20402d9 commit 1c3eb09
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions cmd/soroban-cli/src/commands/events.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use clap::{arg, command, Parser};
use itertools::Itertools;
use soroban_rpc::Event;
use std::io;

use soroban_env_host::xdr::{self, Limits, ReadXdr};
Expand Down Expand Up @@ -155,27 +157,19 @@ impl Cmd {
}

let response = self.run_against_rpc_server(None, None).await?;

for event in &response.events {
match self.output {
// Should we pretty-print the JSON like we're doing here or just
// dump an event in raw JSON on each line? The latter is easier
// to consume programmatically.
OutputFormat::Json => {
println!(
"{}",
serde_json::to_string_pretty(&event).map_err(|e| {
Error::InvalidJson {
debug: format!("{event:#?}"),
error: e,
}
})?,
);
}
OutputFormat::Plain => println!("{event}"),
OutputFormat::Pretty => event.pretty_print()?,
let output = match self.output {
OutputFormat::Json => {
serde_json::to_string_pretty(&response.events).map_err(|e| Error::InvalidJson {
debug: format!("{:#?}", response.events),
error: e,
})?
}
}
OutputFormat::Plain => response.events.iter().join("\n"),
OutputFormat::Pretty => {
return Ok(response.events.iter().try_for_each(Event::pretty_print)?);
}
};
println!("{output}");
Ok(())
}

Expand Down

0 comments on commit 1c3eb09

Please sign in to comment.