mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-25 14:57:32 -05:00
Document cmd
This commit is contained in:
parent
8e178ac60d
commit
32415e1e6c
1 changed files with 7 additions and 0 deletions
|
@ -1,6 +1,8 @@
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use std::{io::Read, path::Path, process::Command};
|
use std::{io::Read, path::Path, process::Command};
|
||||||
|
|
||||||
|
// Run a command with a description for a possible error and append the merged stdout and stderr.
|
||||||
|
// The boolean in the returned `Result` is true if the command's exit status is success.
|
||||||
pub fn run_cmd(mut cmd: Command, description: &str, output: &mut Vec<u8>) -> Result<bool> {
|
pub fn run_cmd(mut cmd: Command, description: &str, output: &mut Vec<u8>) -> Result<bool> {
|
||||||
let (mut reader, writer) = os_pipe::pipe()
|
let (mut reader, writer) = os_pipe::pipe()
|
||||||
.with_context(|| format!("Failed to create a pipe to run the command `{description}``"))?;
|
.with_context(|| format!("Failed to create a pipe to run the command `{description}``"))?;
|
||||||
|
@ -35,13 +37,18 @@ pub struct CargoCmd<'a> {
|
||||||
pub args: &'a [&'a str],
|
pub args: &'a [&'a str],
|
||||||
pub exercise_name: &'a str,
|
pub exercise_name: &'a str,
|
||||||
pub description: &'a str,
|
pub description: &'a str,
|
||||||
|
// RUSTFLAGS="-A warnings"
|
||||||
pub hide_warnings: bool,
|
pub hide_warnings: bool,
|
||||||
|
// Added as `--target-dir` if `Self::dev` is true.
|
||||||
pub target_dir: &'a Path,
|
pub target_dir: &'a Path,
|
||||||
|
// The output buffer to append the merged stdout and stderr.
|
||||||
pub output: &'a mut Vec<u8>,
|
pub output: &'a mut Vec<u8>,
|
||||||
|
// true while developing Rustlings.
|
||||||
pub dev: bool,
|
pub dev: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> CargoCmd<'a> {
|
impl<'a> CargoCmd<'a> {
|
||||||
|
// Run `cargo SUBCOMMAND --bin EXERCISE_NAME … ARGS`.
|
||||||
pub fn run(&mut self) -> Result<bool> {
|
pub fn run(&mut self) -> Result<bool> {
|
||||||
let mut cmd = Command::new("cargo");
|
let mut cmd = Command::new("cargo");
|
||||||
cmd.arg(self.subcommand);
|
cmd.arg(self.subcommand);
|
||||||
|
|
Loading…
Reference in a new issue