Remove filter and dir_action from Details

These two fields were originally needed to determine how to recurse when using tree view.

However, as there was no distinction between the “options parsed from the command-line” Details and the “values needed to render a table” Details, these had to be threaded through the options parser as a special-case to end up in the right struct.

No more! Because there are separate structs for options and rendering, we can just add them in later.
This commit is contained in:
Benjamin Sago 2017-06-26 08:28:32 +01:00
parent 14144e2ad3
commit 65d94636d7
4 changed files with 17 additions and 25 deletions

View File

@ -173,7 +173,7 @@ impl<'w, W: Write + 'w> Exa<'w, W> {
match *mode {
Mode::Lines => lines::Render { files, colours, classify }.render(self.writer),
Mode::Grid(ref opts) => grid::Render { files, colours, classify, opts }.render(self.writer),
Mode::Details(ref opts) => details::Render { dir, files, colours, classify, opts }.render(self.writer),
Mode::Details(ref opts) => details::Render { dir, files, colours, classify, opts, filter: &self.options.filter, recurse: self.options.dir_action.recurse_options() }.render(self.writer),
Mode::GridDetails(ref grid, ref details) => grid_details::Render { dir, files, colours, classify, grid, details }.render(self.writer),
}
}

View File

@ -135,7 +135,7 @@ impl Options {
fn deduce(matches: &getopts::Matches) -> Result<Options, Misfire> {
let dir_action = DirAction::deduce(matches)?;
let filter = FileFilter::deduce(matches)?;
let view = View::deduce(matches, filter.clone(), dir_action)?;
let view = View::deduce(matches)?;
Ok(Options { dir_action, view, filter })
}

View File

@ -6,7 +6,7 @@ use output::Colours;
use output::{grid, details};
use output::column::{Columns, TimeTypes, SizeFormat};
use output::file_name::Classify;
use options::{FileFilter, DirAction, Misfire};
use options::Misfire;
use fs::feature::xattr;
@ -21,8 +21,8 @@ pub struct View {
impl View {
/// Determine which view to use and all of that views arguments.
pub fn deduce(matches: &getopts::Matches, filter: FileFilter, dir_action: DirAction) -> Result<View, Misfire> {
let mode = Mode::deduce(matches, filter, dir_action)?;
pub fn deduce(matches: &getopts::Matches) -> Result<View, Misfire> {
let mode = Mode::deduce(matches)?;
let colours = Colours::deduce(matches)?;
let classify = Classify::deduce(matches);
Ok(View { mode, colours, classify })
@ -42,7 +42,7 @@ pub enum Mode {
impl Mode {
/// Determine the mode from the command-line arguments.
pub fn deduce(matches: &getopts::Matches, filter: FileFilter, dir_action: DirAction) -> Result<Mode, Misfire> {
pub fn deduce(matches: &getopts::Matches) -> Result<Mode, Misfire> {
use options::misfire::Misfire::*;
let long = || {
@ -56,8 +56,6 @@ impl Mode {
let details = details::Options {
columns: Some(Columns::deduce(matches)?),
header: matches.opt_present("header"),
recurse: dir_action.recurse_options(),
filter: filter.clone(),
xattr: xattr::ENABLED && matches.opt_present("extended"),
};
@ -100,8 +98,6 @@ impl Mode {
let details = details::Options {
columns: None,
header: false,
recurse: dir_action.recurse_options(),
filter: filter.clone(), // TODO: clone
xattr: false,
};
@ -125,8 +121,6 @@ impl Mode {
let details = details::Options {
columns: None,
header: false,
recurse: dir_action.recurse_options(),
filter: filter.clone(),
xattr: false,
};

View File

@ -120,14 +120,6 @@ pub struct Options {
/// columns are *added* to this list, such as the Git column.
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`
/// field of the RecurseOptions is `true`.
pub recurse: Option<RecurseOptions>,
/// How to sort and filter the files after getting their details.
pub filter: FileFilter,
/// Whether to show a header line or not.
pub header: bool,
@ -224,6 +216,14 @@ pub struct Render<'a> {
pub colours: &'a Colours,
pub classify: Classify,
pub opts: &'a Options,
/// 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`
/// field of the RecurseOptions is `true`.
pub recurse: Option<RecurseOptions>,
/// How to sort and filter the files after getting their details.
pub filter: &'a FileFilter,
}
impl<'a> Render<'a> {
@ -294,8 +294,6 @@ impl<'a> Render<'a> {
let file_eggs = file_eggs.clone();
let table = table.clone();
let recurse = self.opts.recurse;
scoped.execute(move || {
let mut errors = Vec::new();
let mut xattrs = Vec::new();
@ -315,7 +313,7 @@ impl<'a> Render<'a> {
let mut dir = None;
if let Some(r) = recurse {
if let Some(r) = self.recurse {
if file.is_directory() && r.tree && !r.is_too_deep(depth) {
if let Ok(d) = file.to_dir(false) {
dir = Some(d);
@ -329,7 +327,7 @@ impl<'a> Render<'a> {
}
});
self.opts.filter.sort_files(&mut file_eggs);
self.filter.sort_files(&mut file_eggs);
let num_eggs = file_eggs.len();
for (index, egg) in file_eggs.into_iter().enumerate() {
@ -353,7 +351,7 @@ impl<'a> Render<'a> {
}
}
self.opts.filter.filter_child_files(&mut files);
self.filter.filter_child_files(&mut files);
if !files.is_empty() {
for xattr in egg.xattrs {