mirror of
https://github.com/Llewellynvdm/exa.git
synced 2025-02-05 03:58:25 +00:00
Inline SortField::from_word
With the new OptionSet trait, the from_word constructor doesn't really do much by itself.
This commit is contained in:
parent
10468797bb
commit
8b9f074d63
@ -83,10 +83,7 @@ impl Options {
|
||||
return Err(Misfire::Version);
|
||||
}
|
||||
|
||||
let sort_field = match matches.opt_str("sort") {
|
||||
Some(word) => try!(SortField::from_word(word)),
|
||||
None => SortField::default(),
|
||||
};
|
||||
let sort_field = try!(SortField::deduce(&matches));
|
||||
|
||||
let filter = FileFilter {
|
||||
list_dirs_first: matches.opt_present("group-directories-first"),
|
||||
@ -336,17 +333,7 @@ impl Default for SortField {
|
||||
|
||||
impl OptionSet for SortField {
|
||||
fn deduce(matches: &getopts::Matches) -> Result<SortField, Misfire> {
|
||||
match matches.opt_str("sort") {
|
||||
Some(word) => SortField::from_word(word),
|
||||
None => Ok(SortField::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SortField {
|
||||
|
||||
/// Find which field to use based on a user-supplied word.
|
||||
fn from_word(word: String) -> Result<SortField, Misfire> {
|
||||
if let Some(word) = matches.opt_str("sort") {
|
||||
match &word[..] {
|
||||
"name" | "filename" => Ok(SortField::Name),
|
||||
"size" | "filesize" => Ok(SortField::Size),
|
||||
@ -359,6 +346,13 @@ impl SortField {
|
||||
field => Err(SortField::none(field))
|
||||
}
|
||||
}
|
||||
else {
|
||||
Ok(SortField::default())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SortField {
|
||||
|
||||
/// How to display an error when the word didn't match with anything.
|
||||
fn none(field: &str) -> Misfire {
|
||||
|
Loading…
x
Reference in New Issue
Block a user