mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 14:22:34 +00:00
fix(error): Use a non-generic Error alias
`clap::Error::raw` was producing ambiguity errors with a default generic parameter on `clap::error::Error` (which `clap::Error` is a re-export of). I tried making `clap::Error` a type alias with a default generic parameter but that ran into an ambiguity error with `map_err`. So I'm going ahead and hard coding `clap::Error`. We don't expect people to change this all that often.
This commit is contained in:
parent
c26e7fd617
commit
90bcb7f75e
3 changed files with 13 additions and 7 deletions
|
@ -15,7 +15,7 @@ use crate::output::TAB;
|
|||
/// Defines how to format an error for displaying to the user
|
||||
pub trait ErrorFormatter: Sized {
|
||||
/// Stylize the error for the terminal
|
||||
fn format_error(error: &crate::Error<Self>) -> StyledStr;
|
||||
fn format_error(error: &crate::error::Error<Self>) -> StyledStr;
|
||||
}
|
||||
|
||||
/// Report [`ErrorKind`]
|
||||
|
@ -28,7 +28,7 @@ pub trait ErrorFormatter: Sized {
|
|||
pub struct KindFormatter;
|
||||
|
||||
impl ErrorFormatter for KindFormatter {
|
||||
fn format_error(error: &crate::Error<Self>) -> StyledStr {
|
||||
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() {
|
||||
|
@ -50,7 +50,7 @@ pub struct RawFormatter;
|
|||
|
||||
#[cfg(feature = "error-context")]
|
||||
impl ErrorFormatter for RawFormatter {
|
||||
fn format_error(error: &crate::Error<Self>) -> StyledStr {
|
||||
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() {
|
||||
|
@ -87,7 +87,7 @@ pub struct RichFormatter;
|
|||
|
||||
#[cfg(feature = "error-context")]
|
||||
impl ErrorFormatter for RichFormatter {
|
||||
fn format_error(error: &crate::Error<Self>) -> StyledStr {
|
||||
fn format_error(error: &crate::error::Error<Self>) -> StyledStr {
|
||||
let mut styled = StyledStr::new();
|
||||
start_error(&mut styled);
|
||||
|
||||
|
@ -119,7 +119,7 @@ fn start_error(styled: &mut StyledStr) {
|
|||
|
||||
#[must_use]
|
||||
#[cfg(feature = "error-context")]
|
||||
fn write_dynamic_context(error: &crate::Error, styled: &mut StyledStr) -> bool {
|
||||
fn write_dynamic_context(error: &crate::error::Error, styled: &mut StyledStr) -> bool {
|
||||
match error.kind() {
|
||||
ErrorKind::ArgumentConflict => {
|
||||
let invalid_arg = error.get(ContextKind::InvalidArg);
|
||||
|
|
|
@ -101,7 +101,6 @@ pub use crate::builder::ArgAction;
|
|||
pub use crate::builder::Command;
|
||||
pub use crate::builder::ValueHint;
|
||||
pub use crate::builder::{Arg, ArgGroup};
|
||||
pub use crate::error::Error;
|
||||
pub use crate::parser::ArgMatches;
|
||||
#[cfg(feature = "color")]
|
||||
pub use crate::util::color::ColorChoice;
|
||||
|
@ -110,6 +109,13 @@ pub use crate::util::color::ColorChoice;
|
|||
pub(crate) use crate::util::color::ColorChoice;
|
||||
pub use crate::util::Id;
|
||||
|
||||
/// Command Line Argument Parser Error
|
||||
///
|
||||
/// See [`Command::error`] to create an error.
|
||||
///
|
||||
/// [`Command::error`]: crate::Command::error
|
||||
pub type Error = crate::error::Error<crate::error::DefaultFormatter>;
|
||||
|
||||
pub use crate::derive::{Args, CommandFactory, FromArgMatches, Parser, Subcommand, ValueEnum};
|
||||
|
||||
#[cfg(feature = "derive")]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use super::utils;
|
||||
|
||||
use clap::{arg, error::ErrorKind, value_parser, Arg, Command, Error};
|
||||
use clap::{arg, error::Error, error::ErrorKind, value_parser, Arg, Command};
|
||||
|
||||
#[track_caller]
|
||||
fn assert_error<F: clap::error::ErrorFormatter>(
|
||||
|
|
Loading…
Reference in a new issue