Просмотр исходного кода

Make some options fields private

Benjamin Sago 11 лет назад
Родитель
Сommit
d93bca8779
2 измененных файлов с 16 добавлено и 8 удалено
  1. 7 4
      src/exa.rs
  2. 9 4
      src/options.rs

+ 7 - 4
src/exa.rs

@@ -42,10 +42,14 @@ fn exa(opts: &Options) {
     let mut dirs: Vec<String> = vec![];
     let mut files: Vec<File> = vec![];
 
+    // It's only worth printing out directory names if the user supplied
+    // more than one of them.
+    let mut print_dir_names = false;
+
     // Separate the user-supplied paths into directories and files.
     // Files are shown first, and then each directory is expanded
     // and listed second.
-    for file in opts.path_strs.iter() {
+    for file in opts.path_strings() {
         let path = Path::new(file);
         match fs::stat(&path) {
             Ok(stat) => {
@@ -60,11 +64,10 @@ fn exa(opts: &Options) {
             }
             Err(e) => println!("{}: {}", file, e),
         }
+
+        print_dir_names = true;
     }
 
-    // It's only worth printing out directory names if the user supplied
-    // more than one of them.
-    let print_dir_names = opts.path_strs.len() > 1;
     let mut first = files.is_empty();
 
     if !files.is_empty() {

+ 9 - 4
src/options.rs

@@ -7,6 +7,7 @@ use column::Column::*;
 use term::dimensions;
 
 use std::ascii::AsciiExt;
+use std::slice::Iter;
 
 pub enum SortField {
     Unsorted, Name, Extension, Size, FileInode
@@ -36,10 +37,10 @@ pub enum View {
 pub struct Options {
     pub header: bool,
     pub list_dirs: bool,
-    pub path_strs: Vec<String>,
-    pub reverse: bool,
-    pub show_invisibles: bool,
-    pub sort_field: SortField,
+    path_strs: Vec<String>,
+    reverse: bool,
+    show_invisibles: bool,
+    sort_field: SortField,
     pub view: View,
 }
 
@@ -87,6 +88,10 @@ impl Options {
         })
     }
 
+    pub fn path_strings(&self) -> Iter<String> {
+        self.path_strs.iter()
+    }
+
     fn view(matches: &getopts::Matches) -> View {
         if matches.opt_present("long") {
             View::Details(Options::columns(matches))