mirror of
https://github.com/uutils/coreutils
synced 2024-11-17 18:28:18 +00:00
env: use UResult everywhere
This commit is contained in:
parent
b157a73a1f
commit
db00fab7e4
1 changed files with 9 additions and 16 deletions
25
src/uu/env/src/env.rs
vendored
25
src/uu/env/src/env.rs
vendored
|
@ -23,7 +23,7 @@ use std::io::{self, Write};
|
||||||
use std::iter::Iterator;
|
use std::iter::Iterator;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use uucore::display::Quotable;
|
use uucore::display::Quotable;
|
||||||
use uucore::error::{UResult, USimpleError};
|
use uucore::error::{UResult, USimpleError, UUsageError};
|
||||||
|
|
||||||
const USAGE: &str = "env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]";
|
const USAGE: &str = "env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]";
|
||||||
const AFTER_HELP: &str = "\
|
const AFTER_HELP: &str = "\
|
||||||
|
@ -50,7 +50,7 @@ fn print_env(null: bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_name_value_opt<'a>(opts: &mut Options<'a>, opt: &'a str) -> Result<bool, i32> {
|
fn parse_name_value_opt<'a>(opts: &mut Options<'a>, opt: &'a str) -> UResult<bool> {
|
||||||
// is it a NAME=VALUE like opt ?
|
// is it a NAME=VALUE like opt ?
|
||||||
if let Some(idx) = opt.find('=') {
|
if let Some(idx) = opt.find('=') {
|
||||||
// yes, so push name, value pair
|
// yes, so push name, value pair
|
||||||
|
@ -64,17 +64,12 @@ fn parse_name_value_opt<'a>(opts: &mut Options<'a>, opt: &'a str) -> Result<bool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_program_opt<'a>(opts: &mut Options<'a>, opt: &'a str) -> Result<(), i32> {
|
fn parse_program_opt<'a>(opts: &mut Options<'a>, opt: &'a str) -> UResult<()> {
|
||||||
if opts.null {
|
if opts.null {
|
||||||
eprintln!(
|
Err(UUsageError::new(
|
||||||
"{}: cannot specify --null (-0) with command",
|
125,
|
||||||
uucore::util_name()
|
"cannot specify --null (-0) with command".to_string(),
|
||||||
);
|
))
|
||||||
eprintln!(
|
|
||||||
"Type \"{} --help\" for detailed information",
|
|
||||||
uucore::execution_phrase()
|
|
||||||
);
|
|
||||||
Err(1)
|
|
||||||
} else {
|
} else {
|
||||||
opts.program.push(opt);
|
opts.program.push(opt);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -93,10 +88,8 @@ fn load_config_file(opts: &mut Options) -> UResult<()> {
|
||||||
Ini::load_from_file(file)
|
Ini::load_from_file(file)
|
||||||
};
|
};
|
||||||
|
|
||||||
let conf = conf.map_err(|error| {
|
let conf =
|
||||||
show_error!("{}: {}", file.maybe_quote(), error);
|
conf.map_err(|e| USimpleError::new(1, format!("{}: {}", file.maybe_quote(), e)))?;
|
||||||
1
|
|
||||||
})?;
|
|
||||||
|
|
||||||
for (_, prop) in &conf {
|
for (_, prop) in &conf {
|
||||||
// ignore all INI section lines (treat them as comments)
|
// ignore all INI section lines (treat them as comments)
|
||||||
|
|
Loading…
Reference in a new issue