also use 'env' for printing unsetting
This commit is contained in:
parent
53a29e0e60
commit
fc75f723f6
2 changed files with 4 additions and 8 deletions
|
@ -544,7 +544,7 @@ fn debug_print() {
|
||||||
|
|
||||||
let mut command_with_removed_env = Command::new("boring-name");
|
let mut command_with_removed_env = Command::new("boring-name");
|
||||||
command_with_removed_env.env_remove("FOO").env_remove("BAR");
|
command_with_removed_env.env_remove("FOO").env_remove("BAR");
|
||||||
assert_eq!(format!("{command_with_removed_env:?}"), r#"unset BAR FOO && "boring-name""#);
|
assert_eq!(format!("{command_with_removed_env:?}"), r#"env -u BAR -u FOO "boring-name""#);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
format!("{command_with_removed_env:#?}"),
|
format!("{command_with_removed_env:#?}"),
|
||||||
format!(
|
format!(
|
||||||
|
|
|
@ -562,21 +562,17 @@ impl fmt::Debug for Command {
|
||||||
write!(f, "env -i ")?;
|
write!(f, "env -i ")?;
|
||||||
// Altered env vars will be printed next, that should exactly work as expected.
|
// Altered env vars will be printed next, that should exactly work as expected.
|
||||||
} else {
|
} else {
|
||||||
// Removed env vars need a separate command.
|
// Removed env vars need the command to be wrappen in `env`.
|
||||||
// We use a single `unset` command for all of them.
|
|
||||||
let mut any_removed = false;
|
let mut any_removed = false;
|
||||||
for (key, value_opt) in self.get_envs() {
|
for (key, value_opt) in self.get_envs() {
|
||||||
if value_opt.is_none() {
|
if value_opt.is_none() {
|
||||||
if !any_removed {
|
if !any_removed {
|
||||||
write!(f, "unset ")?;
|
write!(f, "env ")?;
|
||||||
any_removed = true;
|
any_removed = true;
|
||||||
}
|
}
|
||||||
write!(f, "{} ", key.to_string_lossy())?;
|
write!(f, "-u {} ", key.to_string_lossy())?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if any_removed {
|
|
||||||
write!(f, "&& ")?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Altered env vars can just be added in front of the program.
|
// Altered env vars can just be added in front of the program.
|
||||||
for (key, value_opt) in self.get_envs() {
|
for (key, value_opt) in self.get_envs() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue