Skip to content

Commit 054cac6

Browse files
committed
Add option to only display directories
This allows printing directory trees without any files, only showing the structure. I haven't decided on a letter for the short option. Implements #401
1 parent a3b2f2b commit 054cac6

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/fs/filter.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ pub struct FileFilter {
4141
/// ones, depending on the sort field.
4242
pub reverse: bool,
4343

44+
/// Whether to only show directories
45+
pub only_dirs: bool,
46+
4447
/// Which invisible “dot” files to include when listing a directory.
4548
///
4649
/// Files starting with a single “.” are used to determine “system” or
@@ -94,6 +97,10 @@ impl FileFilter {
9497
/// filter predicate for files found inside a directory.
9598
pub fn filter_child_files(&self, files: &mut Vec<File>) {
9699
files.retain(|f| !self.ignore_patterns.is_ignored(&f.name));
100+
101+
if self.only_dirs {
102+
files.retain(|f| f.is_directory());
103+
}
97104
}
98105

99106
/// Remove every file in the given vector that does *not* pass the

src/options/filter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ impl FileFilter {
1414
Ok(FileFilter {
1515
list_dirs_first: matches.has(&flags::DIRS_FIRST)?,
1616
reverse: matches.has(&flags::REVERSE)?,
17+
only_dirs: matches.has(&flags::ONLY_DIRS)?,
1718
sort_field: SortField::deduce(matches)?,
1819
dot_filter: DotFilter::deduce(matches)?,
1920
ignore_patterns: IgnorePatterns::deduce(matches)?,

src/options/flags.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub static SORT: Arg = Arg { short: Some(b's'), long: "sort", take
3030
pub static IGNORE_GLOB: Arg = Arg { short: Some(b'I'), long: "ignore-glob", takes_value: TakesValue::Necessary(None) };
3131
pub static GIT_IGNORE: Arg = Arg { short: None, long: "git-ignore", takes_value: TakesValue::Forbidden };
3232
pub static DIRS_FIRST: Arg = Arg { short: None, long: "group-directories-first", takes_value: TakesValue::Forbidden };
33+
pub static ONLY_DIRS: Arg = Arg { short: None, long: "only-dirs", takes_value: TakesValue::Forbidden };
3334
const SORTS: Values = &[ "name", "Name", "size", "extension",
3435
"Extension", "modified", "accessed",
3536
"created", "inode", "type", "none" ];
@@ -62,7 +63,7 @@ pub static ALL_ARGS: Args = Args(&[
6263
&COLOR, &COLOUR, &COLOR_SCALE, &COLOUR_SCALE,
6364

6465
&ALL, &LIST_DIRS, &LEVEL, &REVERSE, &SORT, &DIRS_FIRST,
65-
&IGNORE_GLOB, &GIT_IGNORE,
66+
&IGNORE_GLOB, &GIT_IGNORE, &ONLY_DIRS,
6667

6768
&BINARY, &BYTES, &GROUP, &HEADER, &INODE, &LINKS, &MODIFIED, &BLOCKS,
6869
&TIME, &ACCESSED, &CREATED, &TIME_STYLE,

0 commit comments

Comments
 (0)