Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,76 @@ impl Command {
self
}

/// Gets an iterator of the arguments that will be passed to the program.
///
/// # Examples
///
/// ```
/// use std::ffi::OsStr;
/// use async_process::Command;
///
/// let mut cmd = Command::new("echo");
/// cmd.arg("first").arg("second");
/// let args: Vec<&OsStr> = cmd.get_args().collect();
/// assert_eq!(args, &["first", "second"]);
/// ```
pub fn get_args(&self) -> std::process::CommandArgs<'_> {
self.inner.get_args()
}

/// Gets an iterator of the environment variables explicitly set for the child process.
///
/// # Examples
///
/// ```
/// use std::ffi::OsStr;
/// use async_process::Command;
///
/// let mut cmd = Command::new("ls");
/// cmd.env("TERM", "dumb").env_remove("TZ");
/// let envs: Vec<(&OsStr, Option<&OsStr>)> = cmd.get_envs().collect();
/// assert_eq!(envs, &[
/// (OsStr::new("TERM"), Some(OsStr::new("dumb"))),
/// (OsStr::new("TZ"), None)
/// ]);
/// ```
pub fn get_envs(&self) -> std::process::CommandEnvs<'_> {
self.inner.get_envs()
}

/// Gets the working directory for the child process.
///
/// This returns [`None`] if the working directory will not be changed.
///
/// # Examples
///
/// ```
/// use std::path::Path;
/// use async_process::Command;
///
/// let mut cmd = Command::new("ls");
/// assert_eq!(cmd.get_current_dir(), None);
/// cmd.current_dir("/bin");
/// assert_eq!(cmd.get_current_dir(), Some(Path::new("/bin")));
/// ```
pub fn get_current_dir(&self) -> Option<&Path> {
self.inner.get_current_dir()
}

/// Gets the path to the program that was given to [`Command::new`].
///
/// # Examples
///
/// ```
/// use async_process::Command;
///
/// let cmd = Command::new("echo");
/// assert_eq!(cmd.get_program(), "echo");
/// ```
pub fn get_program(&self) -> &OsStr {
self.inner.get_program()
}

/// Removes an environment variable mapping.
///
/// # Examples
Expand Down
Loading