Parcourir la source

Allow --tree without --long

This kind of abuses the details view by giving it no columns when the Columns value is None (it's now Optional).
Ben S il y a 10 ans
Parent
commit
e1f4ea9215
3 fichiers modifiés avec 31 ajouts et 10 suppressions
  1. 18 7
      src/options.rs
  2. 8 2
      src/output/details.rs
  3. 5 1
      src/output/grid_details.rs

+ 18 - 7
src/options.rs

@@ -267,11 +267,11 @@ impl View {
             }
             else {
                 let details = Details {
-                        columns: try!(Columns::deduce(matches)),
-                        header: matches.opt_present("header"),
-                        recurse: dir_action.recurse_options().map(|o| (o, filter)),
-                        xattr: Attribute::feature_implemented() && matches.opt_present("extended"),
-                        colours: if dimensions().is_some() { Colours::colourful() } else { Colours::plain() },
+                    columns: Some(try!(Columns::deduce(matches))),
+                    header: matches.opt_present("header"),
+                    recurse: dir_action.recurse_options().map(|o| (o, filter)),
+                    xattr: Attribute::feature_implemented() && matches.opt_present("extended"),
+                    colours: if dimensions().is_some() { Colours::colourful() } else { Colours::plain() },
                 };
 
                 Ok(details)
@@ -279,7 +279,7 @@ impl View {
         };
 
         let long_options_scan = || {
-            for option in &[ "binary", "bytes", "inode", "links", "header", "blocks", "time", "tree", "group" ] {
+            for option in &[ "binary", "bytes", "inode", "links", "header", "blocks", "time", "group" ] {
                 if matches.opt_present(option) {
                     return Err(Useless(option, false, "long"));
                 }
@@ -288,7 +288,7 @@ impl View {
             if cfg!(feature="git") && matches.opt_present("git") {
                 Err(Useless("git", false, "long"))
             }
-            else if matches.opt_present("level") && !matches.opt_present("recurse") {
+            else if matches.opt_present("level") && !matches.opt_present("recurse") && !matches.opt_present("tree") {
                 Err(Useless2("level", "recurse", "tree"))
             }
             else if Attribute::feature_implemented() && matches.opt_present("extended") {
@@ -313,6 +313,17 @@ impl View {
                         Ok(View::Lines(lines))
                     }
                 }
+                else if matches.opt_present("tree") {
+                    let details = Details {
+                        columns: None,
+                        header: false,
+                        recurse: dir_action.recurse_options().map(|o| (o, filter)),
+                        xattr: false,
+                        colours: if dimensions().is_some() { Colours::colourful() } else { Colours::plain() },
+                    };
+
+                    Ok(View::Details(details))
+                }
                 else {
                     let grid = Grid {
                         across: matches.opt_present("across"),

+ 8 - 2
src/output/details.rs

@@ -42,7 +42,7 @@ pub struct Details {
     /// A Columns object that says which columns should be included in the
     /// output in the general case. Directories themselves can pick which
     /// columns are *added* to this list, such as the Git column.
-    pub columns: Columns,
+    pub columns: Option<Columns>,
 
     /// Whether to recurse through directories with a tree view, and if so,
     /// which options to use. This field is only relevant here if the `tree`
@@ -64,7 +64,13 @@ impl Details {
     pub fn view(&self, dir: Option<&Dir>, files: &[File]) {
         // First, transform the Columns object into a vector of columns for
         // the current directory.
-        let mut table = Table::with_options(self.colours, self.columns.for_dir(dir));
+
+        let columns_for_dir = match self.columns {
+            Some(cols) => cols.for_dir(dir),
+            None => Vec::new(),
+        };
+
+        let mut table = Table::with_options(self.colours, columns_for_dir);
         if self.header { table.add_header() }
 
         // Then add files to the table and print it out.

+ 5 - 1
src/output/grid_details.rs

@@ -17,7 +17,11 @@ pub struct GridDetails {
 
 impl GridDetails {
     pub fn view(&self, dir: Option<&Dir>, files: &[File]) {
-        let columns_for_dir = self.details.columns.for_dir(dir);
+        let columns_for_dir = match self.details.columns {
+            Some(cols) => cols.for_dir(dir),
+            None => Vec::new(),
+        };
+
         let mut first_table = Table::with_options(self.details.colours, columns_for_dir.clone());
         let cells: Vec<_> = files.iter().map(|file| first_table.cells_for_file(file)).collect();