Find (Path walker)¶
Effecient git-aware file finder with filtering capabilities.
Uses Linux commands: find, comm and git-ignore for an efficient path walker.
Example usage:
# Simple usage with default root
finder = cli2.Find()
files = finder.files()
dirs = finder.dirs()
# Usage with filters and callback
def callback(filepath):
print(f"Found: {filepath}")
finder = cli2.Find(
root="/path/to/repo",
glob_include=['*.py'],
glob_exclude=['*test*'],
file_callback=callback
)
files = finder.files()
dirs = finder.dirs()
- class cli2.find.Find(root=None, glob_include=None, glob_exclude=None, file_callback=None)[source]¶
A class to walk through files and directories not ignored by git with optional filtering.
- root¶
Root directory for file operations
- glob_include¶
Optional list of glob patterns to include
- glob_exclude¶
Optional list of glob patterns to exclude
- file_callback¶
Optional callback function called for each file or directory
- dirs(directory=None)[source]¶
List directories not ignored by git, applying filters and callback.
- Parameters:
directory (str or pathlib.Path or None) – Directory to start search from (defaults to root if not specified)
- Returns:
List of Path objects for directories not ignored by git that match filters
- Return type:
list
- Raises:
RuntimeError – If the git command fails
- files(directory=None)[source]¶
List files not ignored by git, applying filters and callback.
- Parameters:
directory (str or pathlib.Path or None) – Directory to start search from (defaults to root if not specified)
- Returns:
List of Path objects for files not ignored by git that match filters
- Return type:
list
- Raises:
RuntimeError – If the git command fails