Lots more updates
Also begin adding rust building capabilities to be able to write rust binaries for some commands.
This commit is contained in:
parent
624508dd14
commit
dd1cfa79e7
52 changed files with 2509 additions and 150 deletions
31
rust/lib/common/src/proc/util.rs
Normal file
31
rust/lib/common/src/proc/util.rs
Normal file
|
@ -0,0 +1,31 @@
|
|||
use super::Command;
|
||||
use std::borrow::Cow;
|
||||
|
||||
use shell_quote::Quote;
|
||||
|
||||
pub fn command_to_string(cmd: &Command) -> String {
|
||||
let program = escape_cli(cmd.get_program());
|
||||
let env: Vec<_> = cmd
|
||||
.get_envs()
|
||||
.map(|(key, value)| match value {
|
||||
None => key.into(),
|
||||
Some(value) => Cow::Owned(format!(
|
||||
"{key}={value} ",
|
||||
value = escape_cli(value.as_potentially_redacted_str())
|
||||
)),
|
||||
})
|
||||
.collect();
|
||||
let args: Vec<_> = cmd.get_args().map(escape_cli).collect();
|
||||
let env = env.join("");
|
||||
let args = args.join(" ");
|
||||
format!(
|
||||
"{env_marker}{env}{program}{arg_separator}{args}",
|
||||
env_marker = if env.is_empty() { "" } else { "env " },
|
||||
arg_separator = if args.is_empty() { "" } else { " " }
|
||||
)
|
||||
}
|
||||
|
||||
fn escape_cli<A: AsRef<str>>(str: A) -> String {
|
||||
let str = str.as_ref();
|
||||
shell_quote::Bash::quote(str)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue