mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Add UError impl for clap::Error
This commit is contained in:
parent
979909e371
commit
f40fecf86d
3 changed files with 13 additions and 2 deletions
|
@ -475,7 +475,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
LONG_HELP,
|
LONG_HELP,
|
||||||
backup_control::BACKUP_CONTROL_LONG_HELP
|
backup_control::BACKUP_CONTROL_LONG_HELP
|
||||||
))
|
))
|
||||||
.get_matches_from(args);
|
.try_get_matches_from(args)?;
|
||||||
|
|
||||||
let options = Options::from_matches(&matches)?;
|
let options = Options::from_matches(&matches)?;
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
|
|
||||||
// spell-checker:ignore uioerror
|
// spell-checker:ignore uioerror
|
||||||
|
|
||||||
|
use clap;
|
||||||
use std::{
|
use std::{
|
||||||
error::Error,
|
error::Error,
|
||||||
fmt::{Display, Formatter},
|
fmt::{Display, Formatter},
|
||||||
|
@ -615,3 +616,13 @@ impl From<i32> for Box<dyn UError> {
|
||||||
ExitCode::new(i)
|
ExitCode::new(i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Implementations for clap::Error
|
||||||
|
impl UError for clap::Error {
|
||||||
|
fn code(&self) -> i32 {
|
||||||
|
match self.kind {
|
||||||
|
clap::ErrorKind::DisplayHelp | clap::ErrorKind::DisplayVersion => 0,
|
||||||
|
_ => 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -190,7 +190,7 @@ fn test_cp_target_directory_is_file() {
|
||||||
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
||||||
.arg(TEST_HELLO_WORLD_SOURCE)
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_contains("must specify a directory");
|
.stderr_contains(format!("'{}' is not a directory", TEST_HOW_ARE_YOU_SOURCE));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue