Skip to content

Commit afe1ef0

Browse files
committedJul 19, 2024
uefi: process: Add CommandArgs support
Signed-off-by: Ayush Singh <[email protected]>
1 parent ef6b173 commit afe1ef0

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed
 

‎std/src/sys/pal/uefi/process.rs

+26-14
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::ffi::OsStr;
44
use crate::ffi::OsString;
55
use crate::fmt;
66
use crate::io;
7-
use crate::marker::PhantomData;
87
use crate::num::NonZero;
98
use crate::num::NonZeroI32;
109
use crate::path::Path;
@@ -23,7 +22,7 @@ use super::helpers;
2322

2423
pub struct Command {
2524
prog: OsString,
26-
args: OsString,
25+
args: Vec<OsString>,
2726
stdout: Option<Stdio>,
2827
stderr: Option<Stdio>,
2928
}
@@ -48,15 +47,14 @@ impl Command {
4847
pub fn new(program: &OsStr) -> Command {
4948
Command {
5049
prog: program.to_os_string(),
51-
args: program.to_os_string(),
50+
args: Vec::from([program.to_os_string()]),
5251
stdout: None,
5352
stderr: None,
5453
}
5554
}
5655

5756
pub fn arg(&mut self, arg: &OsStr) {
58-
self.args.push(" ");
59-
self.args.push(arg);
57+
self.args.push(arg.to_os_string());
6058
}
6159

6260
pub fn env_mut(&mut self) -> &mut CommandEnv {
@@ -80,11 +78,11 @@ impl Command {
8078
}
8179

8280
pub fn get_program(&self) -> &OsStr {
83-
panic!("unsupported")
81+
self.prog.as_ref()
8482
}
8583

8684
pub fn get_args(&self) -> CommandArgs<'_> {
87-
panic!("unsupported")
85+
CommandArgs { iter: self.args.iter() }
8886
}
8987

9088
pub fn get_envs(&self) -> CommandEnvs<'_> {
@@ -153,8 +151,15 @@ impl Command {
153151
None => cmd.stderr_inherit(),
154152
};
155153

156-
if !self.args.is_empty() {
157-
cmd.set_args(&self.args);
154+
if self.args.len() > 1 {
155+
let args = self.args.iter().fold(OsString::new(), |mut acc, arg| {
156+
if !acc.is_empty() {
157+
acc.push(" ");
158+
}
159+
acc.push(arg);
160+
acc
161+
});
162+
cmd.set_args(&args);
158163
}
159164

160165
let stat = cmd.start_image()?;
@@ -293,24 +298,31 @@ impl Process {
293298
}
294299

295300
pub struct CommandArgs<'a> {
296-
_p: PhantomData<&'a ()>,
301+
iter: crate::slice::Iter<'a, OsString>,
297302
}
298303

299304
impl<'a> Iterator for CommandArgs<'a> {
300305
type Item = &'a OsStr;
301306
fn next(&mut self) -> Option<&'a OsStr> {
302-
None
307+
self.iter.next().map(|x| x.as_ref())
303308
}
304309
fn size_hint(&self) -> (usize, Option<usize>) {
305-
(0, Some(0))
310+
self.iter.size_hint()
306311
}
307312
}
308313

309-
impl<'a> ExactSizeIterator for CommandArgs<'a> {}
314+
impl<'a> ExactSizeIterator for CommandArgs<'a> {
315+
fn len(&self) -> usize {
316+
self.iter.len()
317+
}
318+
fn is_empty(&self) -> bool {
319+
self.iter.is_empty()
320+
}
321+
}
310322

311323
impl<'a> fmt::Debug for CommandArgs<'a> {
312324
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
313-
f.debug_list().finish()
325+
f.debug_list().entries(self.iter.clone()).finish()
314326
}
315327
}
316328

0 commit comments

Comments
 (0)
Please sign in to comment.