forked from cross-rs/cross
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.rs
43 lines (36 loc) · 1.06 KB
/
cli.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use std::env;
use Target;
use cargo::Subcommand;
use rustc::TargetList;
pub struct Args {
pub all: Vec<String>,
pub subcommand: Option<Subcommand>,
pub target: Option<Target>,
}
pub fn parse(target_list: &TargetList) -> Args {
let all: Vec<_> = env::args().skip(1).collect();
let mut target = None;
let mut sc = None;
{
let mut args = all.iter();
while let Some(arg) = args.next() {
if !arg.starts_with('-') && sc.is_none() {
sc = Some(Subcommand::from(&**arg))
}
if arg == "--target" {
target = args.next().map(|s| Target::from(&**s, target_list))
} else if arg.starts_with("--target=") {
target = arg.splitn(2, '=')
.nth(1)
.map(|s| Target::from(&*s, target_list))
} else if !arg.starts_with('-') && sc.is_none() {
sc = Some(Subcommand::from(&**arg));
}
}
}
Args {
all: all,
subcommand: sc,
target: target,
}
}