@@ -45,12 +45,7 @@ pub enum Stdio {
45
45
46
46
impl Command {
47
47
pub fn new ( program : & OsStr ) -> Command {
48
- Command {
49
- prog : program. to_os_string ( ) ,
50
- args : Vec :: from ( [ program. to_os_string ( ) ] ) ,
51
- stdout : None ,
52
- stderr : None ,
53
- }
48
+ Command { prog : program. to_os_string ( ) , args : Vec :: new ( ) , stdout : None , stderr : None }
54
49
}
55
50
56
51
pub fn arg ( & mut self , arg : & OsStr ) {
@@ -122,6 +117,7 @@ impl Command {
122
117
pub fn output ( & mut self ) -> io:: Result < ( ExitStatus , Vec < u8 > , Vec < u8 > ) > {
123
118
let mut cmd = uefi_command_internal:: Command :: load_image ( & self . prog ) ?;
124
119
120
+ /* Setup Stdout */
125
121
let stdout: Option < helpers:: Protocol < uefi_command_internal:: PipeProtocol > > =
126
122
match self . stdout . take ( ) {
127
123
Some ( s) => Self :: create_pipe ( s) ,
@@ -131,7 +127,12 @@ impl Command {
131
127
)
132
128
. map ( Some ) ,
133
129
} ?;
130
+ match stdout {
131
+ Some ( stdout) => cmd. stdout_init ( stdout) ,
132
+ None => cmd. stdout_inherit ( ) ,
133
+ } ;
134
134
135
+ /* Setup Stderr */
135
136
let stderr: Option < helpers:: Protocol < uefi_command_internal:: PipeProtocol > > =
136
137
match self . stderr . take ( ) {
137
138
Some ( s) => Self :: create_pipe ( s) ,
@@ -141,21 +142,15 @@ impl Command {
141
142
)
142
143
. map ( Some ) ,
143
144
} ?;
144
-
145
- match stdout {
146
- Some ( stdout) => cmd. stdout_init ( stdout) ,
147
- None => cmd. stdout_inherit ( ) ,
148
- } ;
149
145
match stderr {
150
146
Some ( stderr) => cmd. stderr_init ( stderr) ,
151
147
None => cmd. stderr_inherit ( ) ,
152
148
} ;
153
149
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
- }
150
+ /* No reason to set args if only program name is preset */
151
+ if !self . args . is_empty ( ) {
152
+ let args = self . args . iter ( ) . fold ( OsString :: from ( & self . prog ) , |mut acc, arg| {
153
+ acc. push ( " " ) ;
159
154
acc. push ( arg) ;
160
155
acc
161
156
} ) ;
@@ -202,7 +197,11 @@ impl From<File> for Stdio {
202
197
}
203
198
204
199
impl fmt:: Debug for Command {
205
- fn fmt ( & self , _f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
200
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
201
+ self . prog . fmt ( f) ?;
202
+ for arg in & self . args {
203
+ arg. fmt ( f) ?;
204
+ }
206
205
Ok ( ( ) )
207
206
}
208
207
}
@@ -303,9 +302,11 @@ pub struct CommandArgs<'a> {
303
302
304
303
impl < ' a > Iterator for CommandArgs < ' a > {
305
304
type Item = & ' a OsStr ;
305
+
306
306
fn next ( & mut self ) -> Option < & ' a OsStr > {
307
307
self . iter . next ( ) . map ( |x| x. as_ref ( ) )
308
308
}
309
+
309
310
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
310
311
self . iter . size_hint ( )
311
312
}
@@ -315,6 +316,7 @@ impl<'a> ExactSizeIterator for CommandArgs<'a> {
315
316
fn len ( & self ) -> usize {
316
317
self . iter . len ( )
317
318
}
319
+
318
320
fn is_empty ( & self ) -> bool {
319
321
self . iter . is_empty ( )
320
322
}
0 commit comments