base32: use UResult
@@ -11,7 +11,7 @@ extern crate uucore;
use std::io::{stdin, Read};
use clap::App;
-use uucore::encoding::Format;
+use uucore::{encoding::Format, error::UResult};
pub mod base_common;
@@ -24,27 +24,22 @@ static ABOUT: &str = "
to attempt to recover from any other non-alphabet bytes in the
encoded stream.
";
-static VERSION: &str = env!("CARGO_PKG_VERSION");
-
-static BASE_CMD_PARSE_ERROR: i32 = 1;
fn usage() -> String {
format!("{0} [OPTION]... [FILE]", uucore::execution_phrase())
}
-pub fn uumain(args: impl uucore::Args) -> i32 {
+#[uucore_procs::gen_uumain]
+pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let format = Format::Base32;
let usage = usage();
- let name = uucore::util_name();
- let config_result: Result<base_common::Config, String> =
- base_common::parse_base_cmd_args(args, name, VERSION, ABOUT, &usage);
- let config = config_result.unwrap_or_else(|s| crash!(BASE_CMD_PARSE_ERROR, "{}", s));
+ let config: base_common::Config = base_common::parse_base_cmd_args(args, ABOUT, &usage)?;
// Create a reference to stdin so we can return a locked stdin from
// parse_base_cmd_args
let stdin_raw = stdin();
- let mut input: Box<dyn Read> = base_common::get_input(&config, &stdin_raw);
+ let mut input: Box<dyn Read> = base_common::get_input(&config, &stdin_raw)?;
base_common::handle_input(
&mut input,
@@ -52,12 +47,9 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
config.wrap_cols,
config.ignore_garbage,
config.decode,
- name,
- );
-
- 0
+ )
}
pub fn uu_app() -> App<'static, 'static> {
- base_common::base_app(uucore::util_name(), VERSION, ABOUT)
+ base_common::base_app(ABOUT)
}
