|
|
|
@ -223,7 +223,7 @@ impl<U> ArgState<U>
|
|
|
|
|
/// # Note
|
|
|
|
|
/// This mutates the argument state container indefinately, and multiple calls to it will keep the mutated state.
|
|
|
|
|
/// So this might not behave as expected (e.g. callbacks marked `single` that were fired in the first call will not be fired in the second, etc.)
|
|
|
|
|
pub fn parse<I,T: Into<String>>(&mut self, input: I) -> Result<Vec<Box<dyn Any+'static>>, CtxError>
|
|
|
|
|
pub fn parse<I,T: Into<String>>(&mut self, input: I) -> Result<Vec<Box<dyn Any+'static>>, ContextualError>
|
|
|
|
|
where I: Iterator<Item=T>
|
|
|
|
|
{
|
|
|
|
|
let mut output = Vec::with_capacity(self.flags.len());
|
|
|
|
@ -273,19 +273,24 @@ pub struct Error
|
|
|
|
|
/// An argument parsing error with context
|
|
|
|
|
#[repr(transparent)]
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub struct CtxError(Error);
|
|
|
|
|
pub struct ContextualError(Error);
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
|
|
|
pub struct ErrorContext<'a>
|
|
|
|
|
{
|
|
|
|
|
/// The error-throwing flag
|
|
|
|
|
pub flag: &'a Kind<'static>,
|
|
|
|
|
/// The argument string
|
|
|
|
|
pub arg: &'a String,
|
|
|
|
|
/// The index of the argument string
|
|
|
|
|
pub arg_idx: &'a usize,
|
|
|
|
|
/// Message from the failing flag callback, if any
|
|
|
|
|
pub desc: Option<&'a String>,
|
|
|
|
|
/// The error report
|
|
|
|
|
pub from: &'a eyre::Report,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl CtxError
|
|
|
|
|
impl ContextualError
|
|
|
|
|
{
|
|
|
|
|
/// The inner error
|
|
|
|
|
#[inline] pub fn inner(&self) -> &Error
|
|
|
|
@ -343,7 +348,7 @@ impl fmt::Display for Error
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl fmt::Display for CtxError
|
|
|
|
|
impl fmt::Display for ContextualError
|
|
|
|
|
{
|
|
|
|
|
#[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
|
|
|
|
{
|
|
|
|
@ -371,9 +376,9 @@ impl Error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Add context to this error
|
|
|
|
|
pub fn with_context(self) -> CtxError
|
|
|
|
|
pub fn with_context(self) -> ContextualError
|
|
|
|
|
{
|
|
|
|
|
CtxError(Self {
|
|
|
|
|
ContextualError(Self {
|
|
|
|
|
flag: self.flag.clone(),
|
|
|
|
|
arg: self.arg.clone(),
|
|
|
|
|
desc: self.desc.clone(),
|
|
|
|
@ -382,17 +387,17 @@ impl Error
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<Error> for CtxError
|
|
|
|
|
impl From<Error> for ContextualError
|
|
|
|
|
{
|
|
|
|
|
fn from(from: Error) -> Self
|
|
|
|
|
#[inline] fn from(from: Error) -> Self
|
|
|
|
|
{
|
|
|
|
|
from.with_context()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<CtxError> for eyre::Report
|
|
|
|
|
impl From<ContextualError> for eyre::Report
|
|
|
|
|
{
|
|
|
|
|
fn from(from: CtxError) -> Self
|
|
|
|
|
#[inline] fn from(from: ContextualError) -> Self
|
|
|
|
|
{
|
|
|
|
|
from.0.from
|
|
|
|
|
}
|
|
|
|
|