Skip to content

Commit

Permalink
Merge pull request #86 from mufeedvh/fb-full-tree
Browse files Browse the repository at this point in the history
Code2prompt --should-exclude-file flag logic should be by default
  • Loading branch information
ODAncona authored Feb 24, 2025
2 parents 969d136 + a4c121f commit ba2af2d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ struct Cli {
#[clap(short, long)]
template: Option<PathBuf>,

/// 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
///
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 10 additions & 7 deletions src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit ba2af2d

Please sign in to comment.