fix(error): Remove RawFormatter

The likelihood of using this is a lot lower now with `KindFormatter` and
`error-context` feature flag.

People can implement it themselves.
This commit is contained in:
Ed Page 2022-09-20 13:40:16 -05:00
parent 90bcb7f75e
commit 4674e43493
3 changed files with 0 additions and 77 deletions

View file

@ -43,43 +43,6 @@ impl ErrorFormatter for KindFormatter {
}
}
/// Dump the error context reported
#[non_exhaustive]
#[cfg(feature = "error-context")]
pub struct RawFormatter;
#[cfg(feature = "error-context")]
impl ErrorFormatter for RawFormatter {
fn format_error(error: &crate::error::Error<Self>) -> StyledStr {
let mut styled = StyledStr::new();
start_error(&mut styled);
if let Some(msg) = error.kind().as_str() {
styled.none(msg.to_owned());
} else if let Some(source) = error.inner.source.as_ref() {
styled.none(source.to_string());
} else {
styled.none("Unknown cause");
}
styled.none("\n");
if error.context().next().is_some() {
styled.none("\n");
}
for (kind, value) in error.context() {
if let Some(kind) = kind.as_str() {
styled.none(kind);
styled.none(": ");
styled.none(value.to_string());
} else {
styled.none(value.to_string());
}
styled.none("\n");
}
styled
}
}
/// Richly formatted error context
#[non_exhaustive]
#[cfg(feature = "error-context")]

View file

@ -39,8 +39,6 @@ pub use context::ContextKind;
#[cfg(feature = "error-context")]
pub use context::ContextValue;
#[cfg(feature = "error-context")]
pub use format::RawFormatter;
#[cfg(feature = "error-context")]
pub use format::RichFormatter;
#[cfg(not(feature = "error-context"))]

View file

@ -96,25 +96,6 @@ Options:
assert_error(err, expected_kind, MESSAGE, false);
}
#[test]
#[cfg(feature = "error-context")]
fn raw_prints_help() {
let cmd = Command::new("test");
let res = cmd
.try_get_matches_from(["test", "--help"])
.map_err(|e| e.apply::<clap::error::RawFormatter>());
assert!(res.is_err());
let err = res.unwrap_err();
let expected_kind = ErrorKind::DisplayHelp;
static MESSAGE: &str = "\
Usage: test
Options:
-h, --help Print help information
";
assert_error(err, expected_kind, MESSAGE, false);
}
#[test]
fn kind_formats_validation_error() {
let cmd = Command::new("test");
@ -147,22 +128,3 @@ For more information try '--help'
";
assert_error(err, expected_kind, MESSAGE, true);
}
#[test]
#[cfg(feature = "error-context")]
fn raw_formats_validation_error() {
let cmd = Command::new("test");
let res = cmd
.try_get_matches_from(["test", "unused"])
.map_err(|e| e.apply::<clap::error::RawFormatter>());
assert!(res.is_err());
let err = res.unwrap_err();
let expected_kind = ErrorKind::UnknownArgument;
static MESSAGE: &str = "\
error: Found an argument which wasn't expected or isn't valid in this context
Invalid Argument: unused
Usage: test
";
assert_error(err, expected_kind, MESSAGE, true);
}