Skip to content

Commit

Permalink
Allow --tree without --long
Browse files Browse the repository at this point in the history
This kind of abuses the details view by giving it no columns when the Columns value is None (it's now Optional).
  • Loading branch information
ogham committed Aug 3, 2015
1 parent ebbac61 commit e1f4ea9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
25 changes: 18 additions & 7 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,19 +267,19 @@ 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)
}
};

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"));
}
Expand All @@ -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") {
Expand All @@ -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"),
Expand Down
10 changes: 8 additions & 2 deletions src/output/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion src/output/grid_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit e1f4ea9

Please sign in to comment.