mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
Add UError impl for clap::Error
This commit is contained in:
committed by
Sylvestre Ledru
parent
979909e371
commit
f40fecf86d
+1
-1
@@ -475,7 +475,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
LONG_HELP,
|
||||
backup_control::BACKUP_CONTROL_LONG_HELP
|
||||
))
|
||||
.get_matches_from(args);
|
||||
.try_get_matches_from(args)?;
|
||||
|
||||
let options = Options::from_matches(&matches)?;
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
|
||||
// spell-checker:ignore uioerror
|
||||
|
||||
use clap;
|
||||
use std::{
|
||||
error::Error,
|
||||
fmt::{Display, Formatter},
|
||||
@@ -615,3 +616,13 @@ impl From<i32> for Box<dyn UError> {
|
||||
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_HELLO_WORLD_SOURCE)
|
||||
.fails()
|
||||
.stderr_contains("must specify a directory");
|
||||
.stderr_contains(format!("'{}' is not a directory", TEST_HOW_ARE_YOU_SOURCE));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user