diff options
Diffstat (limited to 'src/command.rs')
-rw-r--r-- | src/command.rs | 64 |
1 files changed, 30 insertions, 34 deletions
diff --git a/src/command.rs b/src/command.rs index 8627a35..7ff9858 100644 --- a/src/command.rs +++ b/src/command.rs @@ -1,8 +1,6 @@ -use async_process::unix::CommandExt as _; - -/// Wrapper around [`async_process::Command`] +/// Wrapper around [`tokio::process::Command`] pub struct Command { - inner: async_process::Command, + inner: tokio::process::Command, stdin: bool, stdout: bool, stderr: bool, @@ -13,10 +11,10 @@ pub struct Command { } impl Command { - /// See [`async_process::Command::new`] + /// See [`tokio::process::Command::new`] pub fn new<S: AsRef<std::ffi::OsStr>>(program: S) -> Self { Self { - inner: async_process::Command::new(program), + inner: tokio::process::Command::new(program), stdin: false, stdout: false, stderr: false, @@ -25,13 +23,13 @@ impl Command { } } - /// See [`async_process::Command::arg`] + /// See [`tokio::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`] + /// See [`tokio::process::Command::args`] pub fn args<I, S>(&mut self, args: I) -> &mut Self where I: IntoIterator<Item = S>, @@ -41,7 +39,7 @@ impl Command { self } - /// See [`async_process::Command::env`] + /// See [`tokio::process::Command::env`] pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Self where K: AsRef<std::ffi::OsStr>, @@ -51,7 +49,7 @@ impl Command { self } - /// See [`async_process::Command::envs`] + /// See [`tokio::process::Command::envs`] pub fn envs<I, K, V>(&mut self, vars: I) -> &mut Self where I: IntoIterator<Item = (K, V)>, @@ -62,7 +60,7 @@ impl Command { self } - /// See [`async_process::Command::env_remove`] + /// See [`tokio::process::Command::env_remove`] pub fn env_remove<K: AsRef<std::ffi::OsStr>>( &mut self, key: K, @@ -71,13 +69,13 @@ impl Command { self } - /// See [`async_process::Command::env_clear`] + /// See [`tokio::process::Command::env_clear`] pub fn env_clear(&mut self) -> &mut Self { self.inner.env_clear(); self } - /// See [`async_process::Command::current_dir`] + /// See [`tokio::process::Command::current_dir`] pub fn current_dir<P: AsRef<std::path::Path>>( &mut self, dir: P, @@ -86,7 +84,7 @@ impl Command { self } - /// See [`async_process::Command::stdin`] + /// See [`tokio::process::Command::stdin`] pub fn stdin<T: Into<std::process::Stdio>>( &mut self, cfg: T, @@ -96,7 +94,7 @@ impl Command { self } - /// See [`async_process::Command::stdout`] + /// See [`tokio::process::Command::stdout`] pub fn stdout<T: Into<std::process::Stdio>>( &mut self, cfg: T, @@ -106,7 +104,7 @@ impl Command { self } - /// See [`async_process::Command::stderr`] + /// See [`tokio::process::Command::stderr`] pub fn stderr<T: Into<std::process::Stdio>>( &mut self, cfg: T, @@ -117,27 +115,25 @@ impl Command { } /// 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. + /// [`tokio::process::Command::spawn`] on the given pty. 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 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 + /// [`tokio::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, - ) -> crate::Result<async_process::Child> { - let pts = pty.pts(); - let (stdin, stdout, stderr) = crate::sys::setup_subprocess(pts)?; + pts: &crate::Pts, + ) -> crate::Result<tokio::process::Child> { + let (stdin, stdout, stderr) = pts.0.setup_subprocess()?; if !self.stdin { self.inner.stdin(stdin); @@ -149,7 +145,7 @@ impl Command { self.inner.stderr(stderr); } - let mut session_leader = crate::sys::session_leader(pts); + let mut session_leader = pts.0.session_leader(); // Safety: setsid() is an async-signal-safe function and ioctl() is a // raw syscall (which is inherently async-signal-safe). if let Some(mut custom) = self.pre_exec.take() { @@ -168,19 +164,19 @@ impl Command { Ok(self.inner.spawn()?) } - /// See [`async_process::unix::CommandExt::uid`] + /// See [`tokio::process::Command::uid`] pub fn uid(&mut self, id: u32) -> &mut Self { self.inner.uid(id); self } - /// See [`async_process::unix::CommandExt::gid`] + /// See [`tokio::process::Command::gid`] pub fn gid(&mut self, id: u32) -> &mut Self { self.inner.gid(id); self } - /// See [`async_process::unix::CommandExt::pre_exec`] + /// See [`tokio::process::Command::pre_exec`] #[allow(clippy::missing_safety_doc)] pub unsafe fn pre_exec<F>(&mut self, f: F) -> &mut Self where @@ -190,7 +186,7 @@ impl Command { self } - /// See [`async_process::unix::CommandExt::arg0`] + /// See [`tokio::process::Command::arg0`] pub fn arg0<S>(&mut self, arg: S) -> &mut Self where S: AsRef<std::ffi::OsStr>, |