diff options
Diffstat (limited to 'src/command.rs')
-rw-r--r-- | src/command.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/command.rs b/src/command.rs index 00b51e7..8627a35 100644 --- a/src/command.rs +++ b/src/command.rs @@ -1,5 +1,6 @@ use async_process::unix::CommandExt as _; +/// Wrapper around [`async_process::Command`] pub struct Command { inner: async_process::Command, stdin: bool, @@ -12,6 +13,7 @@ pub struct Command { } impl Command { + /// See [`async_process::Command::new`] pub fn new<S: AsRef<std::ffi::OsStr>>(program: S) -> Self { Self { inner: async_process::Command::new(program), @@ -23,11 +25,13 @@ impl Command { } } + /// See [`async_process::Command::arg`] pub fn arg<S: AsRef<std::ffi::OsStr>>(&mut self, arg: S) -> &mut Self { self.inner.arg(arg); self } + /// See [`async_process::Command::args`] pub fn args<I, S>(&mut self, args: I) -> &mut Self where I: IntoIterator<Item = S>, @@ -37,6 +41,7 @@ impl Command { self } + /// See [`async_process::Command::env`] pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Self where K: AsRef<std::ffi::OsStr>, @@ -46,6 +51,7 @@ impl Command { self } + /// See [`async_process::Command::envs`] pub fn envs<I, K, V>(&mut self, vars: I) -> &mut Self where I: IntoIterator<Item = (K, V)>, @@ -56,6 +62,7 @@ impl Command { self } + /// See [`async_process::Command::env_remove`] pub fn env_remove<K: AsRef<std::ffi::OsStr>>( &mut self, key: K, @@ -64,11 +71,13 @@ impl Command { self } + /// See [`async_process::Command::env_clear`] pub fn env_clear(&mut self) -> &mut Self { self.inner.env_clear(); self } + /// See [`async_process::Command::current_dir`] pub fn current_dir<P: AsRef<std::path::Path>>( &mut self, dir: P, @@ -77,6 +86,7 @@ impl Command { self } + /// See [`async_process::Command::stdin`] pub fn stdin<T: Into<std::process::Stdio>>( &mut self, cfg: T, @@ -86,6 +96,7 @@ impl Command { self } + /// See [`async_process::Command::stdout`] pub fn stdout<T: Into<std::process::Stdio>>( &mut self, cfg: T, @@ -95,6 +106,7 @@ impl Command { self } + /// See [`async_process::Command::stderr`] pub fn stderr<T: Into<std::process::Stdio>>( &mut self, cfg: T, @@ -104,6 +116,22 @@ impl Command { self } + /// Executes the command as a child process via + /// [`async_process::Command::spawn`], and attaches the given `pty` to + /// that child. The pty will be attached to all of `stdin`, `stdout`, and + /// `stderr` of the child, unless those file descriptors were previously + /// overridden through calls to [`stdin`](Self::stdin), + /// [`stdout`](Self::stdout), or [`stderr`](Self::stderr). The newly + /// created child process will also be made the session leader of a new + /// session, and will have the given `pty` instance set as its controlling + /// terminal. + /// + /// # Errors + /// Returns an error if we fail to allocate new file descriptors for + /// attaching the pty to the child process, or if we fail to spawn the + /// child process (see the documentation for + /// [`async_process::Command::spawn`]), or if we fail to make the child a + /// session leader or set its controlling terminal. pub fn spawn( &mut self, pty: &crate::Pty, @@ -140,16 +168,20 @@ impl Command { Ok(self.inner.spawn()?) } + /// See [`async_process::unix::CommandExt::uid`] pub fn uid(&mut self, id: u32) -> &mut Self { self.inner.uid(id); self } + /// See [`async_process::unix::CommandExt::gid`] pub fn gid(&mut self, id: u32) -> &mut Self { self.inner.gid(id); self } + /// See [`async_process::unix::CommandExt::pre_exec`] + #[allow(clippy::missing_safety_doc)] pub unsafe fn pre_exec<F>(&mut self, f: F) -> &mut Self where F: FnMut() -> std::io::Result<()> + Send + Sync + 'static, @@ -158,6 +190,7 @@ impl Command { self } + /// See [`async_process::unix::CommandExt::arg0`] pub fn arg0<S>(&mut self, arg: S) -> &mut Self where S: AsRef<std::ffi::OsStr>, |