@@ -4,7 +4,6 @@ use crate::ffi::OsStr;
44use  crate :: ffi:: OsString ; 
55use  crate :: fmt; 
66use  crate :: io; 
7- use  crate :: marker:: PhantomData ; 
87use  crate :: num:: NonZero ; 
98use  crate :: num:: NonZeroI32 ; 
109use  crate :: path:: Path ; 
@@ -23,7 +22,7 @@ use super::helpers;
2322
2423pub  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
295300pub  struct  CommandArgs < ' a >  { 
296-     _p :   PhantomData < & ' a   ( ) > , 
301+     iter :   crate :: slice :: Iter < ' a ,   OsString > , 
297302} 
298303
299304impl < ' 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
311323impl < ' 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