mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-02 05:57:46 +00:00
basename: use UResult
This commit is contained in:
parent
00769af807
commit
2dc4cba64a
1 changed files with 17 additions and 16 deletions
|
@ -7,11 +7,10 @@
|
||||||
|
|
||||||
// spell-checker:ignore (ToDO) fullname
|
// spell-checker:ignore (ToDO) fullname
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate uucore;
|
|
||||||
|
|
||||||
use clap::{crate_version, App, Arg};
|
use clap::{crate_version, App, Arg};
|
||||||
use std::path::{is_separator, PathBuf};
|
use std::path::{is_separator, PathBuf};
|
||||||
|
use uucore::display::Quotable;
|
||||||
|
use uucore::error::{UResult, UUsageError};
|
||||||
use uucore::InvalidEncodingHandling;
|
use uucore::InvalidEncodingHandling;
|
||||||
|
|
||||||
static SUMMARY: &str = "Print NAME with any leading directory components removed
|
static SUMMARY: &str = "Print NAME with any leading directory components removed
|
||||||
|
@ -32,7 +31,8 @@ pub mod options {
|
||||||
pub static ZERO: &str = "zero";
|
pub static ZERO: &str = "zero";
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uumain(args: impl uucore::Args) -> i32 {
|
#[uucore_procs::gen_uumain]
|
||||||
|
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
let args = args
|
let args = args
|
||||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||||
.accept_any();
|
.accept_any();
|
||||||
|
@ -44,12 +44,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
|
|
||||||
// too few arguments
|
// too few arguments
|
||||||
if !matches.is_present(options::NAME) {
|
if !matches.is_present(options::NAME) {
|
||||||
crash!(
|
return Err(UUsageError::new(1, "missing operand".to_string()));
|
||||||
1,
|
|
||||||
"{1}\nTry '{0} --help' for more information.",
|
|
||||||
uucore::execution_phrase(),
|
|
||||||
"missing operand"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let opt_suffix = matches.is_present(options::SUFFIX);
|
let opt_suffix = matches.is_present(options::SUFFIX);
|
||||||
|
@ -58,12 +53,18 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
let multiple_paths = opt_suffix || opt_multiple;
|
let multiple_paths = opt_suffix || opt_multiple;
|
||||||
// too many arguments
|
// too many arguments
|
||||||
if !multiple_paths && matches.occurrences_of(options::NAME) > 2 {
|
if !multiple_paths && matches.occurrences_of(options::NAME) > 2 {
|
||||||
crash!(
|
return Err(UUsageError::new(
|
||||||
1,
|
1,
|
||||||
"extra operand '{1}'\nTry '{0} --help' for more information.",
|
format!(
|
||||||
uucore::execution_phrase(),
|
"extra operand {}",
|
||||||
matches.values_of(options::NAME).unwrap().nth(2).unwrap()
|
matches
|
||||||
);
|
.values_of(options::NAME)
|
||||||
|
.unwrap()
|
||||||
|
.nth(2)
|
||||||
|
.unwrap()
|
||||||
|
.quote()
|
||||||
|
),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let suffix = if opt_suffix {
|
let suffix = if opt_suffix {
|
||||||
|
@ -89,7 +90,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
print!("{}{}", basename(path, suffix), line_ending);
|
print!("{}{}", basename(path, suffix), line_ending);
|
||||||
}
|
}
|
||||||
|
|
||||||
0
|
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