summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBen S <ogham@bsago.me>2015-11-14 23:47:13 +0000
committerBen S <ogham@bsago.me>2015-11-14 23:47:13 +0000
commit8b9f074d6353ffe3116a65b0d824972d6005f4d0 (patch)
tree21c42a4eab707aae6637d16a234b253a8e574d48 /src
parent10468797bb70f3d16c28127661bb978e5259407c (diff)
Inline SortField::from_word
With the new OptionSet trait, the from_word constructor doesn't really do much by itself.
Diffstat (limited to 'src')
-rw-r--r--src/options.rs38
1 files changed, 16 insertions, 22 deletions
diff --git a/src/options.rs b/src/options.rs
index 79e324f..cc8ae9a 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -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,30 +333,27 @@ 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()),
+ if let Some(word) = matches.opt_str("sort") {
+ 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))
+ }
+ }
+ else {
+ Ok(SortField::default())
}
}
}
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.
fn none(field: &str) -> Misfire {
Misfire::InvalidOptions(getopts::Fail::UnrecognizedOption(format!("--sort {}", field)))