Add manual ignore flag
Signed-off-by: Daniel Henry <iamdanhenry@gmail.com>
This commit is contained in:
@@ -23,7 +23,7 @@ uv tool uninstall dumpy
|
|||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
```
|
```
|
||||||
usage: dumpy.py [-h] [--no-gitignore] [--include-git-dir] [--no-clipboard] [--no-stats]
|
usage: dumpy.py [-h] [--no-gitignore] [--include-git-dir] [--no-clipboard] [--no-stats] [--ignore IGNORE]
|
||||||
|
|
||||||
Dumpy: A tool for providing a text representation of a project formatted in a way that LLMs will understand.
|
Dumpy: A tool for providing a text representation of a project formatted in a way that LLMs will understand.
|
||||||
|
|
||||||
@@ -33,6 +33,7 @@ options:
|
|||||||
--include-git-dir Include the .git directory in the output
|
--include-git-dir Include the .git directory in the output
|
||||||
--no-clipboard Skip putting content into the clipboard and ouput directly to the console
|
--no-clipboard Skip putting content into the clipboard and ouput directly to the console
|
||||||
--no-stats Skip printing stats at the end of the output
|
--no-stats Skip printing stats at the end of the output
|
||||||
|
--ignore IGNORE Comma separated list of patterns to ignore.
|
||||||
```
|
```
|
||||||
|
|
||||||
# Notes
|
# Notes
|
||||||
|
|||||||
22
dumpy.py
22
dumpy.py
@@ -31,8 +31,12 @@ def get_ignore_spec(root: Path):
|
|||||||
return pathspec.PathSpec.from_lines('gitwildmatch', f)
|
return pathspec.PathSpec.from_lines('gitwildmatch', f)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def should_include(path: Path, spec: pathspec.PathSpec | None, root: Path, include_git_dir: bool = False):
|
def should_include(path: Path, spec: pathspec.PathSpec | None, root: Path, include_git_dir: bool = False, manual_ignores = []):
|
||||||
relative_path = path.relative_to(root)
|
relative_path = path.relative_to(root)
|
||||||
|
|
||||||
|
if any(part in manual_ignores for part in path.parts):
|
||||||
|
return False
|
||||||
|
|
||||||
if ".git" in path.parts and not include_git_dir:
|
if ".git" in path.parts and not include_git_dir:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -41,7 +45,7 @@ def should_include(path: Path, spec: pathspec.PathSpec | None, root: Path, inclu
|
|||||||
|
|
||||||
return not spec.match_file(str(relative_path))
|
return not spec.match_file(str(relative_path))
|
||||||
|
|
||||||
def walk_filesystem(ignore_gitignore: bool, include_git_dir: bool = False) -> tuple[int, list[str]]:
|
def walk_filesystem(ignore_gitignore: bool, include_git_dir: bool = False, manual_ignores = []) -> tuple[int, list[str]]:
|
||||||
root = Path(".")
|
root = Path(".")
|
||||||
|
|
||||||
spec = None
|
spec = None
|
||||||
@@ -54,7 +58,7 @@ def walk_filesystem(ignore_gitignore: bool, include_git_dir: bool = False) -> tu
|
|||||||
for path in root.rglob("*"):
|
for path in root.rglob("*"):
|
||||||
if path.is_file():
|
if path.is_file():
|
||||||
# print the filename (for now)
|
# print the filename (for now)
|
||||||
if should_include(path, spec, root, include_git_dir):
|
if should_include(path, spec, root, include_git_dir, manual_ignores):
|
||||||
final_content += generate_metadata_string(path, root)
|
final_content += generate_metadata_string(path, root)
|
||||||
file_count += 1
|
file_count += 1
|
||||||
success, content = get_file_contents(path)
|
success, content = get_file_contents(path)
|
||||||
@@ -100,12 +104,22 @@ def main():
|
|||||||
help="Skip printing stats at the end of the output"
|
help="Skip printing stats at the end of the output"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"--ignore",
|
||||||
|
type=str,
|
||||||
|
help="Comma separated list of patterns to ignore."
|
||||||
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
content: list[str] = []
|
content: list[str] = []
|
||||||
|
|
||||||
content.append(f"Root Directory: {Path(".").absolute()}\n")
|
content.append(f"Root Directory: {Path(".").absolute()}\n")
|
||||||
|
|
||||||
count, content = walk_filesystem(ignore_gitignore=args.no_gitignore)
|
manual_ignores = []
|
||||||
|
if args.ignore:
|
||||||
|
manual_ignores = [item.strip() for item in args.ignore.split(",")]
|
||||||
|
|
||||||
|
count, content = walk_filesystem(ignore_gitignore=args.no_gitignore, manual_ignores=manual_ignores)
|
||||||
string_content = "\n".join(content)
|
string_content = "\n".join(content)
|
||||||
if args.no_clipboard:
|
if args.no_clipboard:
|
||||||
print(string_content)
|
print(string_content)
|
||||||
|
|||||||
Reference in New Issue
Block a user