diff --git a/src/options/misfire.rs b/src/options/misfire.rs index d7e0b50..acba6e0 100644 --- a/src/options/misfire.rs +++ b/src/options/misfire.rs @@ -92,7 +92,7 @@ impl fmt::Display for Misfire { match *self { BadArgument(ref a, ref b, ref c) => write!(f, "Option {} has no value {:?} (Choices: {})", a, b, c), - InvalidOptions(ref e) => write!(f, "{:?}", e), + InvalidOptions(ref e) => write!(f, "{}", e), Help(ref text) => write!(f, "{}", text), Version(ref version) => write!(f, "{}", version), Conflict(ref a, ref b) => write!(f, "Option {} conflicts with option {}.", a, b), @@ -106,3 +106,16 @@ impl fmt::Display for Misfire { } } } + +impl fmt::Display for ParseError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + use self::ParseError::*; + + match *self { + NeedsValue { ref flag } => write!(f, "Flag {} needs a value", flag), + ForbiddenValue { ref flag } => write!(f, "Flag {} cannot take a value", flag), + UnknownShortArgument { ref attempt } => write!(f, "Unknown argument -{}", *attempt as char), + UnknownArgument { ref attempt } => write!(f, "Unknown argument --{}", attempt.to_string_lossy()), + } + } +} diff --git a/src/options/parser.rs b/src/options/parser.rs index 04ea56e..29bd709 100644 --- a/src/options/parser.rs +++ b/src/options/parser.rs @@ -60,6 +60,14 @@ impl Flag { } } +impl fmt::Display for Flag { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + Flag::Short(short) => write!(f, "-{}", short as char), + Flag::Long(long) => write!(f, "--{}", long), + } + } +} /// Whether redundant arguments should be considered a problem. #[derive(PartialEq, Debug, Copy, Clone)] diff --git a/xtests/error_long b/xtests/error_long new file mode 100644 index 0000000..a3bad30 --- /dev/null +++ b/xtests/error_long @@ -0,0 +1 @@ +Unknown argument --ternary diff --git a/xtests/error_overvalued b/xtests/error_overvalued new file mode 100644 index 0000000..b8510a3 --- /dev/null +++ b/xtests/error_overvalued @@ -0,0 +1 @@ +Flag --long cannot take a value diff --git a/xtests/error_short b/xtests/error_short new file mode 100644 index 0000000..1f60b16 --- /dev/null +++ b/xtests/error_short @@ -0,0 +1 @@ +Unknown argument -4 diff --git a/xtests/errors_useless b/xtests/error_useless similarity index 100% rename from xtests/errors_useless rename to xtests/error_useless diff --git a/xtests/error_value b/xtests/error_value new file mode 100644 index 0000000..287ed22 --- /dev/null +++ b/xtests/error_value @@ -0,0 +1 @@ +Flag --time needs a value diff --git a/xtests/run.sh b/xtests/run.sh index c099d1f..fecd51f 100755 --- a/xtests/run.sh +++ b/xtests/run.sh @@ -178,7 +178,11 @@ $exa $testcases/hiddens -l -aa 2>&1 | diff -q - $results/hiddens_laa || exit 1 # Errors -$exa --binary 2>&1 | diff -q - $results/errors_useless || exit 1 +$exa --binary 2>&1 | diff -q - $results/error_useless || exit 1 +$exa --ternary 2>&1 | diff -q - $results/error_long || exit 1 +$exa -4 2>&1 | diff -q - $results/error_short || exit 1 +$exa --time 2>&1 | diff -q - $results/error_value || exit 1 +$exa --long=time 2>&1 | diff -q - $results/error_overvalued || exit 1 # And finally...