Skip to content

Commit 3b39759

Browse files
committed
🐛 Enforce max_depth limit in flat and tree renderers
Add early return in recursive rendering functions to skip nodes beyond max_depth, ensuring the parameter is respected and preventing excessive output or recursion in deep directory structures.
1 parent 484fabc commit 3b39759

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/cedarmapper/render/flat.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ def render_flat(
6161
rows: list[_DisplayRow] = []
6262

6363
def _render_node(node: DirInfo | FileInfo, depth: int, parent_path: str) -> None:
64+
# Only include this node if it's within max_depth
65+
if depth > max_depth:
66+
return
67+
6468
display_path = (
6569
f"{parent_path}{node.path.name}"
6670
if isinstance(node, FileInfo)

src/cedarmapper/render/tree.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ def _render_node(
6262
is_last_stack: list[bool], # stack indicating whether current ancestor is last
6363
parent_display_path: str,
6464
) -> None:
65+
# Only include this node if it's within max_depth
66+
if depth > max_depth:
67+
return
68+
6569
# Build prefix either with numbered indent or with branch characters
6670
if numbered_indent:
6771
prefix = f"{depth:>3} "

0 commit comments

Comments
 (0)