mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-22 12:05:11 +00:00
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:
parent
0fefc78cbb
commit
43bbf00478
@ -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);
|
||||
},
|
||||
|
||||
|
@ -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
2
xtests/error_ltr
Normal 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"
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user