mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +00:00
Merge pull request #2813 from jfinkels/pathchk-uresult
pathchk: return UResult from uumain() function
This commit is contained in:
commit
a285e8bfa9
1 changed files with 17 additions and 27 deletions
|
@ -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,19 +66,13 @@ 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('/') {
|
||||||
|
@ -88,14 +80,12 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
}
|
}
|
||||||
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> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue