mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-22 11:32:27 +00:00
display the command string in a prettier way
This commit is contained in:
parent
0517d8959c
commit
6938ec62fc
2 changed files with 22 additions and 10 deletions
|
@ -9,7 +9,7 @@ use roc_utils::root_dir;
|
|||
use serde::Deserialize;
|
||||
use serde_xml_rs::from_str;
|
||||
use std::env;
|
||||
use std::ffi::OsStr;
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
|
@ -19,7 +19,7 @@ use tempfile::NamedTempFile;
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct Out {
|
||||
pub cmd_str: String, // command with all its arguments, for easy debugging
|
||||
pub cmd_str: OsString, // command with all its arguments, for easy debugging
|
||||
pub stdout: String,
|
||||
pub stderr: String,
|
||||
pub status: ExitStatus,
|
||||
|
@ -158,7 +158,7 @@ where
|
|||
roc_cmd.env(k, v);
|
||||
}
|
||||
|
||||
let roc_cmd_str = format!("{:?}", roc_cmd);
|
||||
let roc_cmd_str = pretty_command_string(&roc_cmd);
|
||||
|
||||
let mut roc_cmd_child = roc_cmd
|
||||
.stdin(Stdio::piped())
|
||||
|
@ -166,7 +166,7 @@ where
|
|||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap_or_else(|err| {
|
||||
panic!("Failed to execute command\n\n {roc_cmd_str}\n\nwith error:\n\n {err}",)
|
||||
panic!("Failed to execute command\n\n {roc_cmd_str:?}\n\nwith error:\n\n {err}",)
|
||||
});
|
||||
|
||||
{
|
||||
|
@ -177,14 +177,14 @@ where
|
|||
.write_all(stdin_str.as_bytes())
|
||||
.unwrap_or_else(|err| {
|
||||
panic!(
|
||||
"Failed to write to stdin for command\n\n {roc_cmd_str}\n\nwith error:\n\n {err}",
|
||||
"Failed to write to stdin for command\n\n {roc_cmd_str:?}\n\nwith error:\n\n {err}",
|
||||
)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let roc_cmd_output = roc_cmd_child.wait_with_output().unwrap_or_else(|err| {
|
||||
panic!("Failed to get output for command\n\n {roc_cmd_str}\n\nwith error:\n\n {err}",)
|
||||
panic!("Failed to get output for command\n\n {roc_cmd_str:?}\n\nwith error:\n\n {err}",)
|
||||
});
|
||||
|
||||
Out {
|
||||
|
@ -207,12 +207,12 @@ pub fn run_cmd<'a, I: IntoIterator<Item = &'a str>, E: IntoIterator<Item = (&'a
|
|||
cmd.arg(arg);
|
||||
}
|
||||
|
||||
let cmd_str = format!("{:?}", cmd);
|
||||
|
||||
for (env, val) in env.into_iter() {
|
||||
cmd.env(env, val);
|
||||
}
|
||||
|
||||
let cmd_str = pretty_command_string(&cmd);
|
||||
|
||||
let mut child = cmd
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
|
@ -279,7 +279,7 @@ pub fn run_with_valgrind<'a, I: IntoIterator<Item = &'a str>>(
|
|||
cmd.arg(arg);
|
||||
}
|
||||
|
||||
let cmd_str = format!("{:?}", cmd);
|
||||
let cmd_str = pretty_command_string(&cmd);
|
||||
|
||||
cmd.stdin(Stdio::piped());
|
||||
cmd.stdout(Stdio::piped());
|
||||
|
@ -447,3 +447,15 @@ pub fn known_bad_file(file_name: &str) -> PathBuf {
|
|||
|
||||
path
|
||||
}
|
||||
|
||||
fn pretty_command_string(command: &Command) -> OsString {
|
||||
let mut command_string = std::ffi::OsString::new();
|
||||
command_string.push(command.get_program());
|
||||
|
||||
for arg in command.get_args() {
|
||||
command_string.push(" ");
|
||||
command_string.push(arg);
|
||||
}
|
||||
|
||||
command_string
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue