use std::ffi::OsStr;
use std::io::Error as IoError;
use std::path::Path;
use std::process;
use std::process::Stdio;
use std::process::{Child, Command};
use ext::{ChildExt, CommandExt, Error, Output};
#[derive(Debug)]
pub struct CheckedChild {
child: Child,
}
impl From<Child> for CheckedChild {
fn from(child: Child) -> CheckedChild {
CheckedChild { child }
}
}
impl CheckedChild {
pub fn as_std_command(&mut self) -> &mut Child {
&mut self.child
}
pub fn into_std_command(self) -> Child {
self.child
}
pub fn stdin(&mut self) -> &mut Option<process::ChildStdin> {
&mut self.child.stdin
}
pub fn stdout(&mut self) -> &mut Option<process::ChildStdout> {
&mut self.child.stdout
}
pub fn stderr(&mut self) -> &mut Option<process::ChildStderr> {
&mut self.child.stderr
}
pub fn kill(&mut self) -> Result<(), IoError> {
self.child.kill()
}
pub fn id(&self) -> u32 {
self.child.id()
}
pub fn wait(&mut self) -> Result<(), Error> {
self.child.checked_wait()
}
#[cfg(feature = "process_try_wait")]
pub fn try_wait(&mut self) -> Result<bool, Error> {
self.child.checked_try_wait()
}
pub fn wait_with_output(self) -> Result<Output, Error> {
self.child.checked_wait_with_output()
}
}
#[derive(Debug)]
pub struct CheckedCommand {
command: Command,
}
impl From<Command> for CheckedCommand {
fn from(command: Command) -> CheckedCommand {
CheckedCommand { command }
}
}
impl CheckedCommand {
pub fn as_std_command(&mut self) -> &mut Command {
&mut self.command
}
pub fn into_std_command(self) -> Command {
self.command
}
pub fn new<S: AsRef<OsStr>>(program: S) -> CheckedCommand {
CheckedCommand {
command: Command::new(program),
}
}
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut CheckedCommand {
self.command.arg(arg);
self
}
pub fn args<I, S>(&mut self, args: I) -> &mut CheckedCommand
where
I: IntoIterator<Item = S>,
S: AsRef<OsStr>,
{
self.command.args(args);
self
}
pub fn env<K, V>(&mut self, key: K, val: V) -> &mut CheckedCommand
where
K: AsRef<OsStr>,
V: AsRef<OsStr>,
{
self.command.env(key, val);
self
}
#[cfg(feature = "command_envs")]
pub fn envs<I, K, V>(&mut self, vars: I) -> &mut CheckedCommand
where
I: IntoIterator<Item = (K, V)>,
K: AsRef<OsStr>,
V: AsRef<OsStr>,
{
self.command.envs(vars);
self
}
pub fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut CheckedCommand {
self.command.env_remove(key);
self
}
pub fn env_clear(&mut self) -> &mut CheckedCommand {
self.command.env_clear();
self
}
pub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut CheckedCommand {
self.command.current_dir(dir);
self
}
pub fn stdin(&mut self, cfg: Stdio) -> &mut CheckedCommand {
self.command.stdin(cfg);
self
}
pub fn stdout(&mut self, cfg: Stdio) -> &mut CheckedCommand {
self.command.stdout(cfg);
self
}
pub fn stderr(&mut self, cfg: Stdio) -> &mut CheckedCommand {
self.command.stderr(cfg);
self
}
pub fn spawn(&mut self) -> Result<CheckedChild, IoError> {
self.command.spawn().map(Into::into)
}
pub fn output(&mut self) -> Result<Output, Error> {
self.command.checked_output()
}
pub fn status(&mut self) -> Result<(), Error> {
self.command.checked_status()
}
}