mirror of
https://github.com/Llewellynvdm/exa.git
synced 2025-01-27 23: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);
|
return Err(Misfire::Version);
|
||||||
}
|
}
|
||||||
|
|
||||||
let sort_field = match matches.opt_str("sort") {
|
let sort_field = try!(SortField::deduce(&matches));
|
||||||
Some(word) => try!(SortField::from_word(word)),
|
|
||||||
None => SortField::default(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let filter = FileFilter {
|
let filter = FileFilter {
|
||||||
list_dirs_first: matches.opt_present("group-directories-first"),
|
list_dirs_first: matches.opt_present("group-directories-first"),
|
||||||
@ -336,30 +333,27 @@ impl Default for SortField {
|
|||||||
|
|
||||||
impl OptionSet for SortField {
|
impl OptionSet for SortField {
|
||||||
fn deduce(matches: &getopts::Matches) -> Result<SortField, Misfire> {
|
fn deduce(matches: &getopts::Matches) -> Result<SortField, Misfire> {
|
||||||
match matches.opt_str("sort") {
|
if let Some(word) = matches.opt_str("sort") {
|
||||||
Some(word) => SortField::from_word(word),
|
match &word[..] {
|
||||||
None => Ok(SortField::default()),
|
"name" | "filename" => Ok(SortField::Name),
|
||||||
|
"size" | "filesize" => Ok(SortField::Size),
|
||||||
|
"ext" | "extension" => Ok(SortField::Extension),
|
||||||
|
"mod" | "modified" => Ok(SortField::ModifiedDate),
|
||||||
|
"acc" | "accessed" => Ok(SortField::AccessedDate),
|
||||||
|
"cr" | "created" => Ok(SortField::CreatedDate),
|
||||||
|
"none" => Ok(SortField::Unsorted),
|
||||||
|
"inode" => Ok(SortField::FileInode),
|
||||||
|
field => Err(SortField::none(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Ok(SortField::default())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SortField {
|
impl SortField {
|
||||||
|
|
||||||
/// Find which field to use based on a user-supplied word.
|
|
||||||
fn from_word(word: String) -> Result<SortField, Misfire> {
|
|
||||||
match &word[..] {
|
|
||||||
"name" | "filename" => Ok(SortField::Name),
|
|
||||||
"size" | "filesize" => Ok(SortField::Size),
|
|
||||||
"ext" | "extension" => Ok(SortField::Extension),
|
|
||||||
"mod" | "modified" => Ok(SortField::ModifiedDate),
|
|
||||||
"acc" | "accessed" => Ok(SortField::AccessedDate),
|
|
||||||
"cr" | "created" => Ok(SortField::CreatedDate),
|
|
||||||
"none" => Ok(SortField::Unsorted),
|
|
||||||
"inode" => Ok(SortField::FileInode),
|
|
||||||
field => Err(SortField::none(field))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// How to display an error when the word didn't match with anything.
|
/// How to display an error when the word didn't match with anything.
|
||||||
fn none(field: &str) -> Misfire {
|
fn none(field: &str) -> Misfire {
|
||||||
Misfire::InvalidOptions(getopts::Fail::UnrecognizedOption(format!("--sort {}", field)))
|
Misfire::InvalidOptions(getopts::Fail::UnrecognizedOption(format!("--sort {}", field)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user