Add accessors to Command.

This commit is contained in:
Eric Huss
2020-09-21 11:32:06 -07:00
parent 623fb90b5a
commit c297e20e03
8 changed files with 303 additions and 8 deletions

View File

@@ -1,10 +1,12 @@
use crate::ffi::OsStr;
use crate::fmt;
use crate::io;
use crate::marker::PhantomData;
use crate::path::Path;
use crate::sys::fs::File;
use crate::sys::pipe::AnonPipe;
use crate::sys::{unsupported, Void};
use crate::sys_common::process::CommandEnv;
use crate::sys_common::process::{CommandEnv, CommandEnvs};
pub use crate::ffi::OsString as EnvKey;
@@ -49,6 +51,22 @@ impl Command {
pub fn stderr(&mut self, _stderr: Stdio) {}
pub fn get_program(&self) -> &OsStr {
panic!("unsupported")
}
pub fn get_args(&self) -> CommandArgs<'_> {
CommandArgs { _p: PhantomData }
}
pub fn get_envs(&self) -> CommandEnvs<'_> {
self.env.iter()
}
pub fn get_current_dir(&self) -> Option<&Path> {
None
}
pub fn spawn(
&mut self,
_default: Stdio,
@@ -147,3 +165,22 @@ impl Process {
match self.0 {}
}
}
pub struct CommandArgs<'a> {
_p: PhantomData<&'a ()>,
}
impl<'a> Iterator for CommandArgs<'a> {
type Item = &'a OsStr;
fn next(&mut self) -> Option<&'a OsStr> {
None
}
}
impl<'a> ExactSizeIterator for CommandArgs<'a> {}
impl<'a> fmt::Debug for CommandArgs<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_list().finish()
}
}