diff --git a/src/main.rs b/src/main.rs index a932476..6f2a307 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,9 +53,9 @@ struct Cli { #[clap(short, long)] template: Option, - /// Exclude files/folders from the source tree based on exclude patterns + /// List the full directory tree #[clap(long)] - exclude_from_tree: bool, + full_directory_tree: bool, /// Optional tokenizer to use for token count /// @@ -163,7 +163,7 @@ fn main() -> Result<()> { args.include_priority, args.line_number, args.relative_paths, - args.exclude_from_tree, + args.full_directory_tree, args.no_codeblock, args.follow_symlinks, args.hidden, diff --git a/src/path.rs b/src/path.rs index 01f48ea..6ffe486 100644 --- a/src/path.rs +++ b/src/path.rs @@ -32,7 +32,7 @@ pub fn traverse_directory( include_priority: bool, line_number: bool, relative_paths: bool, - exclude_from_tree: bool, + full_directory_tree: bool, no_codeblock: bool, follow_symlinks: bool, hidden: bool, @@ -50,18 +50,21 @@ pub fn traverse_directory( .git_ignore(!no_ignore) // By default no_ignore=false, so we invert the flag .follow_links(follow_symlinks) .build() - .filter_map(|entry| entry.ok()) - .filter(|entry| should_include_file(entry.path(), include, exclude, include_priority)) + .filter_map(|entry| match entry { + Ok(entry) + if full_directory_tree + || should_include_file(entry.path(), include, exclude, include_priority) => + { + Some(entry) + } + _ => None, + }) .fold(Tree::new(parent_directory.to_owned()), |mut root, entry| { let path = entry.path(); if let Ok(relative_path) = path.strip_prefix(&canonical_root_path) { // ~~~ Process the tree ~~~ let mut current_tree = &mut root; for component in relative_path.components() { - if exclude_from_tree { - break; - } - let component_str = component.as_os_str().to_string_lossy().to_string(); current_tree = if let Some(pos) = current_tree