Skip to content

Commit

Permalink
refactor: run_cargo_command_with_json
Browse files Browse the repository at this point in the history
  • Loading branch information
BD103 committed May 8, 2024
1 parent 2bf1510 commit 751dd5f
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions tools/ci/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub fn run_cargo_command(
.args(["run", channel.as_str(), "cargo", cargo_command])
.args(args)
.envs(env.iter().copied())
// Execute the command and collect its exit code.
.status()
.map_err(|err| eprintln!("{err}"))
.and_then(status_to_result)
Expand Down Expand Up @@ -107,11 +108,13 @@ pub fn run_cargo_command_with_json(
channel.as_str(),
"cargo",
cargo_command,
// Here we specify that we want JSON output.
"--message-format",
"json",
])
.args(flags)
.envs(env.iter().copied())
// TODO: What's this line doing?
.stdout(Stdio::piped())
.spawn()
.map_err(|err| eprintln!("{err}"))?;
Expand All @@ -121,15 +124,11 @@ pub fn run_cargo_command_with_json(
unreachable!("Child was configured to pipe it's stdout to use but didn't")
};

match JsonCommandOutput::from_cargo_output(command_out, command_name.to_string()) {
Ok(json) => {
let _ = child.wait(); // Don't just leave the child running in the background
Ok(json)
}
Err(err) => {
let _ = child.wait();
eprintln!("{err}");
Err(())
}
}
// Don't just leave the child running in the background.
let _ = child.wait();

JsonCommandOutput::from_cargo_output(command_out, command_name.to_string()).map_err(|err| {
// Log error, converting it to an `Err(())`.
eprintln!("{err}");
})
}

0 comments on commit 751dd5f

Please sign in to comment.