1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

base32: use UResult

This commit is contained in:
Thomas Queiroz 2021-10-02 23:12:09 -03:00
parent 9dd401c358
commit 97df700d67
No known key found for this signature in database
GPG key ID: 229D2DDF7ECA5F8F

View file

@ -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)
}