1
- use std:: env;
1
+ use std:: { env, path :: PathBuf } ;
2
2
3
3
use crate :: Target ;
4
4
use crate :: cargo:: Subcommand ;
@@ -8,29 +8,44 @@ pub struct Args {
8
8
pub all : Vec < String > ,
9
9
pub subcommand : Option < Subcommand > ,
10
10
pub target : Option < Target > ,
11
+ pub target_dir : Option < PathBuf > ,
11
12
}
12
13
13
14
pub fn parse ( target_list : & TargetList ) -> Args {
14
- let all: Vec < _ > = env:: args ( ) . skip ( 1 ) . collect ( ) ;
15
-
16
15
let mut target = None ;
16
+ let mut target_dir = None ;
17
17
let mut sc = None ;
18
+ let mut all: Vec < String > = Vec :: new ( ) ;
18
19
19
20
{
20
- let mut args = all . iter ( ) ;
21
+ let mut args = env :: args ( ) . skip ( 1 ) ;
21
22
while let Some ( arg) = args. next ( ) {
22
- if !arg. starts_with ( '-' ) && sc. is_none ( ) {
23
- sc = Some ( Subcommand :: from ( & * * arg) )
24
- }
25
-
26
23
if arg == "--target" {
27
- target = args. next ( ) . map ( |s| Target :: from ( & * * s, target_list) )
24
+ all. push ( arg) ;
25
+ if let Some ( t) = args. next ( ) {
26
+ target = Some ( Target :: from ( & t, target_list) ) ;
27
+ all. push ( t) ;
28
+ }
28
29
} else if arg. starts_with ( "--target=" ) {
29
- target = arg. splitn ( 2 , '=' )
30
- . nth ( 1 )
31
- . map ( |s| Target :: from ( & * s, target_list) )
32
- } else if !arg. starts_with ( '-' ) && sc. is_none ( ) {
33
- sc = Some ( Subcommand :: from ( & * * arg) ) ;
30
+ target = arg. splitn ( 2 , '=' ) . nth ( 1 ) . map ( |s| Target :: from ( & * s, target_list) ) ;
31
+ all. push ( arg) ;
32
+ } else if arg == "--target-dir" {
33
+ all. push ( arg) ;
34
+ if let Some ( td) = args. next ( ) {
35
+ target_dir = Some ( PathBuf :: from ( & td) ) ;
36
+ all. push ( "/target" . to_string ( ) ) ;
37
+ }
38
+ } else if arg. starts_with ( "--target-dir=" ) {
39
+ if let Some ( td) = arg. splitn ( 2 , '=' ) . nth ( 1 ) {
40
+ target_dir = Some ( PathBuf :: from ( & td) ) ;
41
+ all. push ( format ! ( "--target-dir=/target" ) ) ;
42
+ }
43
+ } else {
44
+ if !arg. starts_with ( '-' ) && sc. is_none ( ) {
45
+ sc = Some ( Subcommand :: from ( arg. as_ref ( ) ) ) ;
46
+ }
47
+
48
+ all. push ( arg. to_string ( ) ) ;
34
49
}
35
50
}
36
51
}
@@ -39,5 +54,6 @@ pub fn parse(target_list: &TargetList) -> Args {
39
54
all,
40
55
subcommand : sc,
41
56
target,
57
+ target_dir,
42
58
}
43
59
}
0 commit comments