Skip to content

Commit 5407cff

Browse files
committed
feat: try type-specific extensions when resolving -i/-w from .treemapper/
1 parent 23470d9 commit 5407cff

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/treemapper/cli.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,13 @@ def _resolve_output_file(output_file_arg: str | None, save: bool, output_format:
8282
return output_file, False
8383

8484

85-
def _find_in_treemapper_dir(arg: str, root_dir: Path) -> Path | None:
86-
if Path(arg).parent == Path("."):
87-
candidate = root_dir / ".treemapper" / arg
85+
def _find_in_treemapper_dir(arg: str, root_dir: Path, extra_exts: tuple[str, ...]) -> Path | None:
86+
if Path(arg).parent != Path("."):
87+
return None
88+
stem = Path(arg).stem if Path(arg).suffix else arg
89+
base = root_dir / ".treemapper"
90+
for name in (arg, *(f"{stem}{ext}" for ext in extra_exts if f"{stem}{ext}" != arg)):
91+
candidate = base / name
8892
if candidate.is_file():
8993
return candidate
9094
return None
@@ -93,7 +97,7 @@ def _find_in_treemapper_dir(arg: str, root_dir: Path) -> Path | None:
9397
def _resolve_ignore_file(ignore_file_arg: str | None, root_dir: Path) -> Path | None:
9498
if not ignore_file_arg:
9599
return None
96-
found = _find_in_treemapper_dir(ignore_file_arg, root_dir)
100+
found = _find_in_treemapper_dir(ignore_file_arg, root_dir, (".ignore", ".txt"))
97101
if found:
98102
return found
99103
resolved = Path(ignore_file_arg).resolve()
@@ -105,7 +109,7 @@ def _resolve_ignore_file(ignore_file_arg: str | None, root_dir: Path) -> Path |
105109
def _resolve_whitelist_file(whitelist_file_arg: str | None, root_dir: Path) -> Path | None:
106110
if not whitelist_file_arg:
107111
return None
108-
found = _find_in_treemapper_dir(whitelist_file_arg, root_dir)
112+
found = _find_in_treemapper_dir(whitelist_file_arg, root_dir, (".whitelist", ".txt"))
109113
if found:
110114
return found
111115
resolved = Path(whitelist_file_arg).resolve()

0 commit comments

Comments
 (0)