Add Command::get_env_clear
This addition allows an end-user to inspect whether the env clear value is set on a `Command` instance or not. Discussed in: - https://github.com/rust-lang/rust/issues/149070 - https://github.com/rust-lang/libs-team/issues/194
This commit is contained in:
parent
3d461af2a2
commit
b6a6f00a2d
6 changed files with 44 additions and 0 deletions
|
|
@ -1206,6 +1206,30 @@ impl Command {
|
|||
pub fn get_current_dir(&self) -> Option<&Path> {
|
||||
self.inner.get_current_dir()
|
||||
}
|
||||
|
||||
/// Returns whether the environment will be cleared for the child process.
|
||||
///
|
||||
/// This returns `true` if [`Command::env_clear`] was called, and `false` otherwise.
|
||||
/// When `true`, the child process will not inherit any environment variables from
|
||||
/// its parent process.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(command_resolved_envs)]
|
||||
/// use std::process::Command;
|
||||
///
|
||||
/// let mut cmd = Command::new("ls");
|
||||
/// assert_eq!(cmd.get_env_clear(), false);
|
||||
///
|
||||
/// cmd.env_clear();
|
||||
/// assert_eq!(cmd.get_env_clear(), true);
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[unstable(feature = "command_resolved_envs", issue = "149070")]
|
||||
pub fn get_env_clear(&self) -> bool {
|
||||
self.inner.get_env_clear()
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
|
|
|||
|
|
@ -98,6 +98,10 @@ impl Command {
|
|||
self.env.iter()
|
||||
}
|
||||
|
||||
pub fn get_env_clear(&self) -> bool {
|
||||
self.env.does_clear()
|
||||
}
|
||||
|
||||
pub fn get_current_dir(&self) -> Option<&Path> {
|
||||
self.cwd.as_ref().map(Path::new)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,6 +83,10 @@ impl Command {
|
|||
self.env.iter()
|
||||
}
|
||||
|
||||
pub fn get_env_clear(&self) -> bool {
|
||||
self.env.does_clear()
|
||||
}
|
||||
|
||||
pub fn get_current_dir(&self) -> Option<&Path> {
|
||||
None
|
||||
}
|
||||
|
|
|
|||
|
|
@ -263,6 +263,10 @@ impl Command {
|
|||
self.env.iter()
|
||||
}
|
||||
|
||||
pub fn get_env_clear(&self) -> bool {
|
||||
self.env.does_clear()
|
||||
}
|
||||
|
||||
pub fn get_current_dir(&self) -> Option<&Path> {
|
||||
self.cwd.as_ref().map(|cs| Path::new(OsStr::from_bytes(cs.as_bytes())))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,6 +86,10 @@ impl Command {
|
|||
self.env.iter()
|
||||
}
|
||||
|
||||
pub fn get_env_clear(&self) -> bool {
|
||||
self.env.does_clear()
|
||||
}
|
||||
|
||||
pub fn get_current_dir(&self) -> Option<&Path> {
|
||||
self.cwd.as_ref().map(|cs| Path::new(cs))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -250,6 +250,10 @@ impl Command {
|
|||
self.env.iter()
|
||||
}
|
||||
|
||||
pub fn get_env_clear(&self) -> bool {
|
||||
self.env.does_clear()
|
||||
}
|
||||
|
||||
pub fn get_current_dir(&self) -> Option<&Path> {
|
||||
self.cwd.as_ref().map(Path::new)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue