diff --git a/src/options.rs b/src/options.rs index cc8ae9a..e16d698 100644 --- a/src/options.rs +++ b/src/options.rs @@ -343,7 +343,7 @@ impl OptionSet for SortField { "cr" | "created" => Ok(SortField::CreatedDate), "none" => Ok(SortField::Unsorted), "inode" => Ok(SortField::FileInode), - field => Err(SortField::none(field)) + field => Err(Misfire::bad_argument("sort", field)) } } else { @@ -352,14 +352,6 @@ impl OptionSet for SortField { } } -impl SortField { - - /// 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))) - } -} - impl OptionSet for SizeFormat { @@ -418,7 +410,7 @@ impl OptionSet for TimeTypes { "mod" | "modified" => Ok(TimeTypes { accessed: false, modified: true, created: false }), "acc" | "accessed" => Ok(TimeTypes { accessed: true, modified: false, created: false }), "cr" | "created" => Ok(TimeTypes { accessed: false, modified: false, created: true }), - otherwise => Err(Misfire::InvalidOptions(getopts::Fail::UnrecognizedOption(format!("--time {}", otherwise)))), + otherwise => Err(Misfire::bad_argument("time", otherwise)), } } else { @@ -539,11 +531,20 @@ pub enum Misfire { } impl Misfire { + /// The OS return code this misfire should signify. pub fn error_code(&self) -> i32 { if let Misfire::Help(_) = *self { 2 } else { 3 } } + + /// The Misfire that happens when an option gets given the wrong + /// argument. This has to use one of the `getopts` failure + /// variants--it’s meant to take just an option name, rather than an + /// option *and* an argument, but it works just as well. + pub fn bad_argument(option: &str, otherwise: &str) -> Misfire { + Misfire::InvalidOptions(getopts::Fail::UnrecognizedOption(format!("--{} {}", option, otherwise))) + } } impl fmt::Display for Misfire {