env: use UResult everywhere
@@ -23,7 +23,7 @@ use std::io::{self, Write};
use std::iter::Iterator;
use std::process::Command;
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 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 ?
if let Some(idx) = opt.find('=') {
// 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 {
- eprintln!(
- "{}: cannot specify --null (-0) with command",
- uucore::util_name()
- );
- eprintln!(
- "Type \"{} --help\" for detailed information",
- uucore::execution_phrase()
- );
- Err(1)
+ Err(UUsageError::new(
+ 125,
+ "cannot specify --null (-0) with command".to_string(),
+ ))
} else {
opts.program.push(opt);
Ok(())
@@ -93,10 +88,8 @@ fn load_config_file(opts: &mut Options) -> UResult<()> {
Ini::load_from_file(file)
};
- let conf = conf.map_err(|error| {
- show_error!("{}: {}", file.maybe_quote(), error);
- 1
- })?;
+ let conf =
+ conf.map_err(|e| USimpleError::new(1, format!("{}: {}", file.maybe_quote(), e)))?;
for (_, prop) in &conf {
// ignore all INI section lines (treat them as comments)
