瀏覽代碼

Add reverse parameter

Ben S 11 年之前
父節點
當前提交
d60c2ce839
共有 2 個文件被更改,包括 6 次插入0 次删除
  1. 5 0
      exa.rs
  2. 1 0
      options.rs

+ 5 - 0
exa.rs

@@ -24,6 +24,7 @@ fn main() {
 
     let opts = ~[
         getopts::optflag("a", "all", "show dot-files"),
+        getopts::optflag("r", "reverse", "reverse order of files"),
         getopts::optopt("s", "sort", "field to sort by", "WORD"),
     ];
 
@@ -34,6 +35,7 @@ fn main() {
 
     let opts = Options {
         showInvisibles: matches.opt_present("all"),
+        reverse: matches.opt_present("reverse"),
         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();
     options.sort(&mut files);
+    if options.reverse {
+        files.reverse();
+    }
 
     let columns = defaultColumns();
     let table: Vec<Vec<StrBuf>> = files.iter()

+ 1 - 0
options.rs

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