mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-26 15:26:29 +00:00
Check the status of the cargo metadata
command
This commit is contained in:
parent
e41c3a7c92
commit
337460d299
1 changed files with 10 additions and 6 deletions
16
src/cmd.rs
16
src/cmd.rs
|
@ -1,4 +1,4 @@
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::{
|
use std::{
|
||||||
io::Read,
|
io::Read,
|
||||||
|
@ -68,12 +68,16 @@ impl CmdRunner {
|
||||||
.stdin(Stdio::null())
|
.stdin(Stdio::null())
|
||||||
.stderr(Stdio::inherit())
|
.stderr(Stdio::inherit())
|
||||||
.output()
|
.output()
|
||||||
.context(CARGO_METADATA_ERR)?
|
.context(CARGO_METADATA_ERR)?;
|
||||||
.stdout;
|
|
||||||
|
|
||||||
let target_dir = serde_json::de::from_slice::<CargoMetadata>(&metadata_output)
|
if !metadata_output.status.success() {
|
||||||
.context("Failed to read the field `target_directory` from the `cargo metadata` output")
|
bail!("The command `cargo metadata …` failed. Are you in the `rustlings/` directory?");
|
||||||
.map(|metadata| metadata.target_directory)?;
|
}
|
||||||
|
|
||||||
|
let target_dir = serde_json::de::from_slice::<CargoMetadata>(&metadata_output.stdout)
|
||||||
|
.context(
|
||||||
|
"Failed to read the field `target_directory` from the output of the command `cargo metadata …`",
|
||||||
|
)?.target_directory;
|
||||||
|
|
||||||
Ok(Self { target_dir })
|
Ok(Self { target_dir })
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue