Show a warning when running ‘exa -ltr’

Raised in #243 and #284. exa isn’t able to override the -t option like this, so the least it can do is detect that case (which is going to be an error case anyway) and show a suggestion.
This commit is contained in:
Benjamin Sago 2017-09-13 23:47:19 +01:00
parent 0fefc78cbb
commit 43bbf00478
4 changed files with 25 additions and 2 deletions

View File

@ -28,7 +28,13 @@ fn main() {
},
Err(ref e) if e.is_error() => {
writeln!(stderr(), "{}", e).unwrap();
let mut stderr = stderr();
writeln!(stderr, "{}", e).unwrap();
if let Some(s) = e.suggestion() {
let _ = writeln!(stderr, "{}", s);
}
exit(exits::OPTIONS_ERROR);
},

View File

@ -4,7 +4,7 @@ use std::num::ParseIntError;
use glob;
use options::{HelpString, VersionString};
use options::{flags, HelpString, VersionString};
use options::parser::{Arg, Flag, ParseError};
@ -120,3 +120,15 @@ impl fmt::Display for ParseError {
}
}
}
impl Misfire {
pub fn suggestion(&self) -> Option<&'static str> {
if let Misfire::BadArgument(ref time, ref r, ref _choices) = *self {
if *time == &flags::TIME && r == "r" {
return Some("To sort newest files first, try \"--sort modified\", or just \"-stime\"");
}
}
None
}
}

2
xtests/error_ltr Normal file
View File

@ -0,0 +1,2 @@
Option --time (-t) has no "r" setting (choices: modified, accessed, created)
To sort newest files first, try "--sort modified", or just "-stime"

View File

@ -263,6 +263,9 @@ $exa -l --long 2>&1 | diff -q - $results/error_duplicate || exit 1
$exa -ll 2>&1 | diff -q - $results/error_twice || exit 1
$exa -l --time-style=24 2>&1 | diff -q - $results/error_setting || exit 1
# Error suggestions
$exa -ltr 2>&1 | diff -q - $results/error_ltr || exit 1
# Debug mode
# (uses an empty directory so it prints nothing to stdout)