Skip to content

Commit e1f4ea9

Browse files
committed
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).
1 parent ebbac61 commit e1f4ea9

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

src/options.rs

+18-7
Original file line numberDiff line numberDiff line change
@@ -267,19 +267,19 @@ impl View {
267267
}
268268
else {
269269
let details = Details {
270-
columns: try!(Columns::deduce(matches)),
271-
header: matches.opt_present("header"),
272-
recurse: dir_action.recurse_options().map(|o| (o, filter)),
273-
xattr: Attribute::feature_implemented() && matches.opt_present("extended"),
274-
colours: if dimensions().is_some() { Colours::colourful() } else { Colours::plain() },
270+
columns: Some(try!(Columns::deduce(matches))),
271+
header: matches.opt_present("header"),
272+
recurse: dir_action.recurse_options().map(|o| (o, filter)),
273+
xattr: Attribute::feature_implemented() && matches.opt_present("extended"),
274+
colours: if dimensions().is_some() { Colours::colourful() } else { Colours::plain() },
275275
};
276276

277277
Ok(details)
278278
}
279279
};
280280

281281
let long_options_scan = || {
282-
for option in &[ "binary", "bytes", "inode", "links", "header", "blocks", "time", "tree", "group" ] {
282+
for option in &[ "binary", "bytes", "inode", "links", "header", "blocks", "time", "group" ] {
283283
if matches.opt_present(option) {
284284
return Err(Useless(option, false, "long"));
285285
}
@@ -288,7 +288,7 @@ impl View {
288288
if cfg!(feature="git") && matches.opt_present("git") {
289289
Err(Useless("git", false, "long"))
290290
}
291-
else if matches.opt_present("level") && !matches.opt_present("recurse") {
291+
else if matches.opt_present("level") && !matches.opt_present("recurse") && !matches.opt_present("tree") {
292292
Err(Useless2("level", "recurse", "tree"))
293293
}
294294
else if Attribute::feature_implemented() && matches.opt_present("extended") {
@@ -313,6 +313,17 @@ impl View {
313313
Ok(View::Lines(lines))
314314
}
315315
}
316+
else if matches.opt_present("tree") {
317+
let details = Details {
318+
columns: None,
319+
header: false,
320+
recurse: dir_action.recurse_options().map(|o| (o, filter)),
321+
xattr: false,
322+
colours: if dimensions().is_some() { Colours::colourful() } else { Colours::plain() },
323+
};
324+
325+
Ok(View::Details(details))
326+
}
316327
else {
317328
let grid = Grid {
318329
across: matches.opt_present("across"),

src/output/details.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub struct Details {
4242
/// A Columns object that says which columns should be included in the
4343
/// output in the general case. Directories themselves can pick which
4444
/// columns are *added* to this list, such as the Git column.
45-
pub columns: Columns,
45+
pub columns: Option<Columns>,
4646

4747
/// Whether to recurse through directories with a tree view, and if so,
4848
/// which options to use. This field is only relevant here if the `tree`
@@ -64,7 +64,13 @@ impl Details {
6464
pub fn view(&self, dir: Option<&Dir>, files: &[File]) {
6565
// First, transform the Columns object into a vector of columns for
6666
// the current directory.
67-
let mut table = Table::with_options(self.colours, self.columns.for_dir(dir));
67+
68+
let columns_for_dir = match self.columns {
69+
Some(cols) => cols.for_dir(dir),
70+
None => Vec::new(),
71+
};
72+
73+
let mut table = Table::with_options(self.colours, columns_for_dir);
6874
if self.header { table.add_header() }
6975

7076
// Then add files to the table and print it out.

src/output/grid_details.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ pub struct GridDetails {
1717

1818
impl GridDetails {
1919
pub fn view(&self, dir: Option<&Dir>, files: &[File]) {
20-
let columns_for_dir = self.details.columns.for_dir(dir);
20+
let columns_for_dir = match self.details.columns {
21+
Some(cols) => cols.for_dir(dir),
22+
None => Vec::new(),
23+
};
24+
2125
let mut first_table = Table::with_options(self.details.colours, columns_for_dir.clone());
2226
let cells: Vec<_> = files.iter().map(|file| first_table.cells_for_file(file)).collect();
2327

0 commit comments

Comments
 (0)