1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-30 12:37:49 +00:00

pathchk: return UResult from uumain() function

This commit is contained in:
Jeffrey Finkelstein 2021-12-28 20:36:58 -05:00
parent f7584cb755
commit fcd5c0a30f

View file

@ -8,14 +8,11 @@
// * that was distributed with this source code. // * that was distributed with this source code.
// spell-checker:ignore (ToDO) lstat // spell-checker:ignore (ToDO) lstat
#[macro_use]
extern crate uucore;
use clap::{crate_version, App, Arg}; use clap::{crate_version, App, Arg};
use std::fs; use std::fs;
use std::io::{ErrorKind, Write}; use std::io::{ErrorKind, Write};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{set_exit_code, UResult, UUsageError};
use uucore::InvalidEncodingHandling; use uucore::InvalidEncodingHandling;
// operating mode // operating mode
@ -43,7 +40,8 @@ fn usage() -> String {
format!("{0} [OPTION]... NAME...", uucore::execution_phrase()) format!("{0} [OPTION]... NAME...", uucore::execution_phrase())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { #[uucore_procs::gen_uumain]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let usage = usage();
let args = args let args = args
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
@ -68,34 +66,26 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
// take necessary actions // take necessary actions
let paths = matches.values_of(options::PATH); let paths = matches.values_of(options::PATH);
let mut res = if paths.is_none() { if paths.is_none() {
show_error!( return Err(UUsageError::new(1, "missing operand"));
"missing operand\nTry '{} --help' for more information", }
uucore::execution_phrase()
);
false
} else {
true
};
if res { // free strings are path operands
// free strings are path operands // FIXME: TCS, seems inefficient and overly verbose (?)
// FIXME: TCS, seems inefficient and overly verbose (?) let mut res = true;
for p in paths.unwrap() { for p in paths.unwrap() {
let mut path = Vec::new(); let mut path = Vec::new();
for path_segment in p.split('/') { for path_segment in p.split('/') {
path.push(path_segment.to_string()); path.push(path_segment.to_string());
}
res &= check_path(&mode, &path);
} }
res &= check_path(&mode, &path);
} }
// determine error code // determine error code
if res { if !res {
0 set_exit_code(1);
} else {
1
} }
Ok(())
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {