Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
urso committed Apr 10, 2020
1 parent 7c3da09 commit 4102930
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ RUN cargo install cross
currently only available for the overlayfs2 storage driver. In order to access
the parent containers rust setup, the child container mounts the parents
overlayfs. The parent must not be stopped before the child container, as the
overlayfs can not be unmounted correctly by docker if the child container still
overlayfs can not be unmounted correctly by Docker if the child container still
accesses it.


Expand Down
38 changes: 7 additions & 31 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ pub fn parse(target_list: &TargetList) -> Args {
all.push(t);
}
} else if arg.starts_with("--target=") {
target = arg.splitn(2, '=').nth(1).map(|s| Target::from(&*s, target_list));
target = arg
.splitn(2, '=')
.nth(1)
.map(|s| Target::from(&*s, target_list));
all.push(arg);
} else if arg == "--target-dir" {
all.push(arg);
Expand All @@ -52,7 +55,9 @@ pub fn parse(target_list: &TargetList) -> Args {
}
}

let docker_in_docker = parse_bool_env(env::var("CROSS_DOCKER_IN_DOCKER"));
let docker_in_docker = env::var("CROSS_DOCKER_IN_DOCKER")
.map(|s| bool::from_str(&s).unwrap_or_default())
.unwrap_or_default();

Args {
all,
Expand All @@ -62,32 +67,3 @@ pub fn parse(target_list: &TargetList) -> Args {
docker_in_docker,
}
}

fn parse_bool_env(val: Result<String, env::VarError>) -> bool {
val.map(|s| bool::from_str(&s).unwrap_or_default())
.unwrap_or_default()
}

#[cfg(test)]
mod tests {
use super::*;
use std::env::VarError;

#[test]
fn test_env_bool_default_to_false() {
let input = Err(VarError::NotPresent);
assert_eq!(false, parse_bool_env(input));
}

#[test]
fn test_docker_in_docker_if_true() {
let input = Ok(String::from("true"));
assert_eq!(true, parse_bool_env(input));
}

#[test]
fn test_no_docker_in_docker_if_false() {
let input = Ok(String::from("false"));
assert_eq!(false, parse_bool_env(input));
}
}

0 comments on commit 4102930

Please sign in to comment.