@@ -42,24 +42,24 @@ struct CopyOperation {
42
42
43
43
/// Parse command line arguments and transform into `CopyOperation`
44
44
fn parse_args ( args : Vec < & str > ) -> io:: Result < CopyOperation > {
45
- if !( ( args. len ( ) == 4 || args. len ( ) == 5 && args[ 2 ] . eq ( "-a" ) ) && args [ 1 ] . eq ( "cp ") ) {
45
+ if !( args. len ( ) == 3 || args. len ( ) == 4 && args[ 1 ] . eq ( "-a" ) ) {
46
46
return Err ( io:: Error :: new (
47
47
io:: ErrorKind :: InvalidInput ,
48
48
"Invalid parameters. Expected cp [-a] <source> <destination>" ,
49
49
) ) ;
50
50
}
51
51
52
- if args. len ( ) == 5 {
52
+ if args. len ( ) == 4 {
53
53
return Ok ( CopyOperation {
54
- source : PathBuf :: from ( args[ 3 ] ) ,
55
- destination : PathBuf :: from ( args[ 4 ] ) ,
54
+ source : PathBuf :: from ( args[ 2 ] ) ,
55
+ destination : PathBuf :: from ( args[ 3 ] ) ,
56
56
copy_type : CopyType :: Archive ,
57
57
} ) ;
58
58
}
59
59
60
60
Ok ( CopyOperation {
61
- source : PathBuf :: from ( args[ 2 ] ) ,
62
- destination : PathBuf :: from ( args[ 3 ] ) ,
61
+ source : PathBuf :: from ( args[ 1 ] ) ,
62
+ destination : PathBuf :: from ( args[ 2 ] ) ,
63
63
copy_type : CopyType :: SingleFile ,
64
64
} )
65
65
}
@@ -143,7 +143,7 @@ mod tests {
143
143
#[ test]
144
144
fn test_parser_archive ( ) {
145
145
// prepare
146
- let input = vec ! [ "cp-utility" , "cp ", "-a" , "foo.txt" , "dest.txt" ] ;
146
+ let input = vec ! [ "cp" , "-a" , "foo.txt" , "dest.txt" ] ;
147
147
148
148
// act
149
149
let result = parse_args ( input) . unwrap ( ) ;
@@ -157,7 +157,7 @@ mod tests {
157
157
#[ test]
158
158
fn test_parser_single ( ) {
159
159
// prepare
160
- let input: Vec < & str > = vec ! [ "cp-utility" , "cp ", "foo.txt" , "dest.txt" ] ;
160
+ let input: Vec < & str > = vec ! [ "cp" , "foo.txt" , "dest.txt" ] ;
161
161
162
162
// act
163
163
let result = parse_args ( input) . unwrap ( ) ;
@@ -172,11 +172,9 @@ mod tests {
172
172
fn parser_failure ( ) {
173
173
// prepare
174
174
let inputs = vec ! [
175
- vec![ "cp-utility" , "cp" , "-r" , "foo.txt" , "bar.txt" ] ,
176
- vec![ "cp-utility" , "cp" , "-a" , "param1" , "param2" , "param3" ] ,
177
- vec![ "cp-utility" , "cp" , "param1" , "param2" , "param3" ] ,
178
- vec![ "cp-utility" , "mv" , "param1" , "param2" ] ,
179
- vec![ "cp-utility" , "mv" , "-a" , "param1" , "param2" ] ,
175
+ vec![ "cp" , "-r" , "foo.txt" , "bar.txt" ] ,
176
+ vec![ "cp" , "-a" , "param1" , "param2" , "param3" ] ,
177
+ vec![ "cp" , "param1" , "param2" , "param3" ] ,
180
178
] ;
181
179
182
180
for input in inputs. into_iter ( ) {
0 commit comments