1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

cp: let clap render help & version

This commit is contained in:
Daniel Hofstetter 2025-06-16 15:54:13 +02:00
parent 19e04a26cf
commit 7ffc16c31d

View file

@ -23,7 +23,7 @@ use thiserror::Error;
use platform::copy_on_write;
use uucore::display::Quotable;
use uucore::error::{UClapError, UError, UResult, UUsageError, set_exit_code};
use uucore::error::{UError, UResult, UUsageError, set_exit_code};
#[cfg(unix)]
use uucore::fs::make_fifo;
use uucore::fs::{
@ -796,20 +796,8 @@ pub fn uu_app() -> Command {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(args);
let mut matches = uu_app().try_get_matches_from(args)?;
// The error is parsed here because we do not want version or help being printed to stderr.
if let Err(e) = matches {
let mut app = uu_app();
match e.kind() {
clap::error::ErrorKind::DisplayHelp => {
app.print_help()?;
}
clap::error::ErrorKind::DisplayVersion => print!("{}", app.render_version()),
_ => return Err(Box::new(e.with_exit_code(1))),
};
} else if let Ok(mut matches) = matches {
let options = Options::from_matches(&matches)?;
if options.overwrite == OverwriteMode::NoClobber && options.backup != BackupMode::None {
@ -836,7 +824,6 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
};
set_exit_code(EXIT_ERR);
}
}
Ok(())
}