|
@@ -37,18 +37,38 @@ pub enum OptionsError {
|
|
|
TreeAllAll,
|
|
TreeAllAll,
|
|
|
|
|
|
|
|
/// A numeric option was given that failed to be parsed as a number.
|
|
/// A numeric option was given that failed to be parsed as a number.
|
|
|
- FailedParse(ParseIntError),
|
|
|
|
|
|
|
+ FailedParse(String, NumberSource, ParseIntError),
|
|
|
|
|
|
|
|
/// A glob ignore was given that failed to be parsed as a pattern.
|
|
/// A glob ignore was given that failed to be parsed as a pattern.
|
|
|
FailedGlobPattern(String),
|
|
FailedGlobPattern(String),
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/// The source of a string that failed to be parsed as a number.
|
|
|
|
|
+#[derive(PartialEq, Debug)]
|
|
|
|
|
+pub enum NumberSource {
|
|
|
|
|
+
|
|
|
|
|
+ /// It came... from a command-line argument!
|
|
|
|
|
+ Arg(&'static Arg),
|
|
|
|
|
+
|
|
|
|
|
+ /// It came... from the enviroment!
|
|
|
|
|
+ Env(&'static str),
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
impl From<glob::PatternError> for OptionsError {
|
|
impl From<glob::PatternError> for OptionsError {
|
|
|
fn from(error: glob::PatternError) -> Self {
|
|
fn from(error: glob::PatternError) -> Self {
|
|
|
Self::FailedGlobPattern(error.to_string())
|
|
Self::FailedGlobPattern(error.to_string())
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+impl fmt::Display for NumberSource {
|
|
|
|
|
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
|
+ match self {
|
|
|
|
|
+ Self::Arg(arg) => write!(f, "option {}", arg),
|
|
|
|
|
+ Self::Env(env) => write!(f, "environment variable {}", env),
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
impl fmt::Display for OptionsError {
|
|
impl fmt::Display for OptionsError {
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
use crate::options::parser::TakesValue;
|
|
use crate::options::parser::TakesValue;
|
|
@@ -71,7 +91,7 @@ impl fmt::Display for OptionsError {
|
|
|
Self::Useless(a, true, b) => write!(f, "Option {} is useless given option {}", a, b),
|
|
Self::Useless(a, true, b) => write!(f, "Option {} is useless given option {}", a, b),
|
|
|
Self::Useless2(a, b1, b2) => write!(f, "Option {} is useless without options {} or {}", a, b1, b2),
|
|
Self::Useless2(a, b1, b2) => write!(f, "Option {} is useless without options {} or {}", a, b1, b2),
|
|
|
Self::TreeAllAll => write!(f, "Option --tree is useless given --all --all"),
|
|
Self::TreeAllAll => write!(f, "Option --tree is useless given --all --all"),
|
|
|
- Self::FailedParse(ref e) => write!(f, "Failed to parse number: {}", e),
|
|
|
|
|
|
|
+ Self::FailedParse(s, n, e) => write!(f, "Value {:?} not valid for {}: {}", s, n, e),
|
|
|
Self::FailedGlobPattern(ref e) => write!(f, "Failed to parse glob pattern: {}", e),
|
|
Self::FailedGlobPattern(ref e) => write!(f, "Failed to parse glob pattern: {}", e),
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|