From 4c16f505654f2c2b04d9811b4a92b7ae1107f026 Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Sat, 19 Aug 2017 22:17:53 +0100 Subject: [PATCH] Fix an error being displayed weirdly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Debug impl was being used instead of the Display one. Also, remove the full stops from the ends of all the error messages because I’ve decided it looks weird. --- src/options/misfire.rs | 13 +++++++------ xtests/error_duplicate | 1 + xtests/error_twice | 1 + xtests/error_useless | 2 +- xtests/run.sh | 2 ++ 5 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 xtests/error_duplicate create mode 100644 xtests/error_twice diff --git a/src/options/misfire.rs b/src/options/misfire.rs index acba6e0..9df110b 100644 --- a/src/options/misfire.rs +++ b/src/options/misfire.rs @@ -95,12 +95,13 @@ impl fmt::Display for Misfire { 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), - Duplicate(ref a, ref b) => write!(f, "Flag {:?} conflicts with flag {:?}.", a, b), - Useless(ref a, false, ref b) => write!(f, "Option {} is useless without option {}.", a, b), - Useless(ref a, true, ref b) => write!(f, "Option {} is useless given option {}.", a, b), - Useless2(ref a, ref b1, ref b2) => write!(f, "Option {} is useless without options {} or {}.", a, b1, b2), - TreeAllAll => write!(f, "Option --tree is useless given --all --all."), + Conflict(ref a, ref b) => write!(f, "Option {} conflicts with option {}", a, b), + Duplicate(ref a, ref b) => if a == b { write!(f, "Flag {} was given twice", a) } + else { write!(f, "Flag {} conflicts with flag {}", a, b) }, + Useless(ref a, false, ref b) => write!(f, "Option {} is useless without option {}", a, b), + Useless(ref a, true, ref b) => write!(f, "Option {} is useless given option {}", a, b), + Useless2(ref a, ref b1, ref b2) => write!(f, "Option {} is useless without options {} or {}", a, b1, b2), + TreeAllAll => write!(f, "Option --tree is useless given --all --all"), FailedParse(ref e) => write!(f, "Failed to parse number: {}", e), FailedGlobPattern(ref e) => write!(f, "Failed to parse glob pattern: {}", e), } diff --git a/xtests/error_duplicate b/xtests/error_duplicate new file mode 100644 index 0000000..9ef8ce7 --- /dev/null +++ b/xtests/error_duplicate @@ -0,0 +1 @@ +Flag -l conflicts with flag --long diff --git a/xtests/error_twice b/xtests/error_twice new file mode 100644 index 0000000..99ef3fd --- /dev/null +++ b/xtests/error_twice @@ -0,0 +1 @@ +Flag -l was given twice diff --git a/xtests/error_useless b/xtests/error_useless index 74fed7e..08e4e63 100644 --- a/xtests/error_useless +++ b/xtests/error_useless @@ -1 +1 @@ -Option --binary (-b) is useless without option --long (-l). +Option --binary (-b) is useless without option --long (-l) diff --git a/xtests/run.sh b/xtests/run.sh index c5b49e2..d97cd45 100755 --- a/xtests/run.sh +++ b/xtests/run.sh @@ -189,6 +189,8 @@ $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 +$exa -l --long 2>&1 | diff -q - $results/error_duplicate || exit 1 +$exa -ll 2>&1 | diff -q - $results/error_twice || exit 1 # Debug mode