diff --git a/src/lib.rs b/src/lib.rs index ecaff5b09..6080888df 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -99,8 +99,10 @@ extern crate mio; #[macro_use] extern crate log; +use std::ffi::OsStr; use std::io::{self, Read, Write}; -use std::process::{ExitStatus, Command, Output, Stdio}; +use std::path::Path; +use std::process::{self, ExitStatus, Output, Stdio}; use futures::{Future, Poll, IntoFuture}; use futures::future::{Flatten, FutureResult, Either, ok}; @@ -183,7 +185,7 @@ pub trait CommandExt { } -impl CommandExt for Command { +impl CommandExt for process::Command { fn spawn_async(&mut self, handle: &Handle) -> io::Result { let mut child = Child { child: imp::Child::new(try!(self.spawn()), handle), @@ -441,3 +443,102 @@ impl Read for ChildStderr { self.inner.read(bytes) } } + +// deprecated from 0.1.0 + +#[deprecated(note = "use std::process::Command instead")] +#[allow(deprecated, missing_docs)] +pub struct Command { + inner: process::Command, + #[allow(dead_code)] + handle: Handle, +} + +#[deprecated(note = "use std::process::Command instead")] +#[allow(deprecated, missing_docs)] +pub struct Spawn { + inner: Box>, +} + +#[deprecated(note = "use std::process::Command instead")] +#[allow(deprecated, missing_docs)] +impl Command { + pub fn new>(exe: T, handle: &Handle) -> Command { + Command::_new(exe.as_ref(), handle) + } + + fn _new(exe: &OsStr, handle: &Handle) -> Command { + Command { + inner: process::Command::new(exe), + handle: handle.clone(), + } + } + + pub fn arg>(&mut self, arg: S) -> &mut Command { + self._arg(arg.as_ref()) + } + + fn _arg(&mut self, arg: &OsStr) -> &mut Command { + self.inner.arg(arg); + self + } + + pub fn args>(&mut self, args: &[S]) -> &mut Command { + for arg in args { + self._arg(arg.as_ref()); + } + self + } + + pub fn env(&mut self, key: K, val: V) -> &mut Command + where K: AsRef, V: AsRef + { + self._env(key.as_ref(), val.as_ref()) + } + + fn _env(&mut self, key: &OsStr, val: &OsStr) -> &mut Command { + self.inner.env(key, val); + self + } + + pub fn env_remove>(&mut self, key: K) -> &mut Command { + self._env_remove(key.as_ref()) + } + + fn _env_remove(&mut self, key: &OsStr) -> &mut Command { + self.inner.env_remove(key); + self + } + + pub fn env_clear(&mut self) -> &mut Command { + self.inner.env_clear(); + self + } + + pub fn current_dir>(&mut self, dir: P) -> &mut Command { + self._current_dir(dir.as_ref()) + } + + fn _current_dir(&mut self, dir: &Path) -> &mut Command { + self.inner.current_dir(dir); + self + } + + pub fn spawn(mut self) -> Spawn { + Spawn { + inner: self.inner.spawn_async(&self.handle).into_future().boxed() + } + } +} + +#[deprecated(note = "use std::process::Command instead")] +#[allow(deprecated)] +impl Future for Spawn { + type Item = Child; + type Error = io::Error; + + fn poll(&mut self) -> Poll { + self.inner.poll() + } +} +