Add reverse parameter

This commit is contained in:
Ben S 2014-05-24 21:45:24 +01:00
parent 4d1aea12b0
commit d60c2ce839
2 changed files with 6 additions and 0 deletions

5
exa.rs
View File

@ -24,6 +24,7 @@ fn main() {
let opts = ~[ let opts = ~[
getopts::optflag("a", "all", "show dot-files"), getopts::optflag("a", "all", "show dot-files"),
getopts::optflag("r", "reverse", "reverse order of files"),
getopts::optopt("s", "sort", "field to sort by", "WORD"), getopts::optopt("s", "sort", "field to sort by", "WORD"),
]; ];
@ -34,6 +35,7 @@ fn main() {
let opts = Options { let opts = Options {
showInvisibles: matches.opt_present("all"), showInvisibles: matches.opt_present("all"),
reverse: matches.opt_present("reverse"),
sortField: matches.opt_str("sort").map(|word| SortField::from_word(word)).unwrap_or(Name), sortField: matches.opt_str("sort").map(|word| SortField::from_word(word)).unwrap_or(Name),
}; };
@ -57,6 +59,9 @@ fn list(options: Options, path: Path) {
let mut files = paths.iter().map(|path| File::from_path(path)).collect(); let mut files = paths.iter().map(|path| File::from_path(path)).collect();
options.sort(&mut files); options.sort(&mut files);
if options.reverse {
files.reverse();
}
let columns = defaultColumns(); let columns = defaultColumns();
let table: Vec<Vec<StrBuf>> = files.iter() let table: Vec<Vec<StrBuf>> = files.iter()

View File

@ -8,6 +8,7 @@ pub enum SortField {
pub struct Options { pub struct Options {
pub showInvisibles: bool, pub showInvisibles: bool,
pub sortField: SortField, pub sortField: SortField,
pub reverse: bool,
} }
impl SortField { impl SortField {