Lots more updates

Also begin adding rust building capabilities
to be able to write rust binaries for some commands.
This commit is contained in:
Kaare Hoff Skovgaard 2025-07-06 22:37:16 +02:00
parent 624508dd14
commit dd1cfa79e7
Signed by: khs
GPG key ID: C7D890804F01E9F0
52 changed files with 2509 additions and 150 deletions

View 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)
}