@@ -141,10 +141,10 @@ pub fn parse_command<S: Into<String>>(
141
141
if command_string. is_empty ( ) {
142
142
return Ok ( None ) ;
143
143
}
144
- let argv = shell_words:: split ( & command_string) ?;
144
+ let mut argv = shell_words:: split ( & command_string) ?;
145
145
Ok ( Some ( (
146
146
Command {
147
- program : argv[ 0 ] . clone ( ) ,
147
+ program : argv. remove ( 0 ) ,
148
148
argv,
149
149
} ,
150
150
command_string,
@@ -308,15 +308,15 @@ mod test {
308
308
let ( command, command_string) = parse_command ( "ls" . to_string ( ) ) . unwrap ( ) . unwrap ( ) ;
309
309
assert_eq ! ( "ls" , command_string) ;
310
310
assert_eq ! ( "ls" , command. program) ;
311
- assert_eq ! ( vec! [ "ls" ] , command. argv) ;
311
+ assert_eq ! ( Vec :: < String > :: new ( ) , command. argv) ;
312
312
}
313
313
314
314
#[ test]
315
315
fn parse_command_handles_commands_with_args ( ) {
316
316
let ( command, command_string) = parse_command ( "ls -al" . to_string ( ) ) . unwrap ( ) . unwrap ( ) ;
317
317
assert_eq ! ( "ls -al" , command_string) ;
318
318
assert_eq ! ( "ls" , command. program) ;
319
- assert_eq ! ( vec![ "ls" , " -al"] , command. argv) ;
319
+ assert_eq ! ( vec![ "-al" ] , command. argv) ;
320
320
}
321
321
322
322
#[ test]
@@ -326,7 +326,7 @@ mod test {
326
326
. unwrap ( ) ;
327
327
assert_eq ! ( "hello world" , command_string) ;
328
328
assert_eq ! ( "hello" , command. program) ;
329
- assert_eq ! ( vec![ "hello" , " world"] , command. argv) ;
329
+ assert_eq ! ( vec![ "world" ] , command. argv) ;
330
330
}
331
331
332
332
#[ test]
@@ -337,9 +337,6 @@ mod test {
337
337
. unwrap ( ) ;
338
338
assert_eq ! ( "find . -type \" f\" -name '*.rs'" , command_string) ;
339
339
assert_eq ! ( "find" , command. program) ;
340
- assert_eq ! (
341
- vec![ "find" , "." , "-type" , "f" , "-name" , "*.rs" ] ,
342
- command. argv
343
- ) ;
340
+ assert_eq ! ( vec![ "." , "-type" , "f" , "-name" , "*.rs" ] , command. argv) ;
344
341
}
345
342
}
0 commit comments