1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2026-01-18 03:01:06 +00:00

env: clean up returning Err

This commit is contained in:
Jeong YunWon 2021-06-11 14:23:14 +09:00
parent 6736faec4a
commit f01121f5b7

18
src/uu/env/src/env.rs vendored
View file

@ -82,13 +82,10 @@ fn load_config_file(opts: &mut Options) -> Result<(), i32> {
Ini::load_from_file(file)
};
let conf = match conf {
Ok(config) => config,
Err(error) => {
eprintln!("env: error: \"{}\": {}", file, error);
return Err(1);
}
};
let conf = conf.map_err(|error| {
eprintln!("env: error: \"{}\": {}", file, error);
1
})?;
for (_, prop) in &conf {
// ignore all INI section lines (treat them as comments)
@ -256,13 +253,10 @@ fn run_env(args: impl uucore::Args) -> Result<(), i32> {
// FIXME: this should just use execvp() (no fork()) on Unix-like systems
match Command::new(&*prog).args(args).status() {
Ok(exit) => {
if !exit.success() {
return Err(exit.code().unwrap());
}
}
Ok(exit) if !exit.success() => return Err(exit.code().unwrap()),
Err(ref err) if err.kind() == io::ErrorKind::NotFound => return Err(127),
Err(_) => return Err(126),
Ok(_) => (),
}
} else {
// no program provided, so just dump all env vars to stdout