diff --git a/src/config.py b/src/config.py index 7365ab8b..2be0c498 100644 --- a/src/config.py +++ b/src/config.py @@ -8,9 +8,11 @@ MAX_TOTAL_SIZE_BYTES = 500 * 1024 * 1024 # 500 MB MAX_DISPLAY_SIZE: int = 300_000 -TMP_BASE_PATH = Path("/tmp/gitingest") DELETE_REPO_AFTER: int = 60 * 60 # In seconds +OUTPUT_FILE_PATH = "digest.txt" +TMP_BASE_PATH = Path("/tmp/gitingest") + EXAMPLE_REPOS: list[dict[str, str]] = [ {"name": "Gitingest", "url": "https://github.com/cyclotruc/gitingest"}, {"name": "FastAPI", "url": "https://github.com/tiangolo/fastapi"}, diff --git a/src/gitingest/cli.py b/src/gitingest/cli.py index a21a4533..18a0e106 100644 --- a/src/gitingest/cli.py +++ b/src/gitingest/cli.py @@ -6,7 +6,7 @@ import click -from config import MAX_FILE_SIZE +from config import MAX_FILE_SIZE, OUTPUT_FILE_PATH from gitingest.repository_ingest import ingest @@ -84,7 +84,7 @@ async def _async_main( include_patterns = set(include_pattern) if not output: - output = "digest.txt" + output = OUTPUT_FILE_PATH summary, _, _ = await ingest(source, max_size, include_patterns, exclude_patterns, output=output) click.echo(f"Analysis complete! Output written to: {output}") diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 00000000..86bd2271 --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,41 @@ +""" Tests for the gitingest cli """ + +import os + +from click.testing import CliRunner + +from config import MAX_FILE_SIZE, OUTPUT_FILE_PATH +from gitingest.cli import main + + +def test_cli_with_default_options(): + runner = CliRunner() + result = runner.invoke(main, ["./"]) + output_lines = result.output.strip().split("\n") + assert f"Analysis complete! Output written to: {OUTPUT_FILE_PATH}" in output_lines + assert os.path.exists(OUTPUT_FILE_PATH), f"Output file was not created at {OUTPUT_FILE_PATH}" + + os.remove(OUTPUT_FILE_PATH) + + +def test_cli_with_options(): + runner = CliRunner() + result = runner.invoke( + main, + [ + "./", + "--output", + OUTPUT_FILE_PATH, + "--max-size", + MAX_FILE_SIZE, + "--exclude-pattern", + "tests/", + "--include-pattern", + "src/", + ], + ) + output_lines = result.output.strip().split("\n") + assert f"Analysis complete! Output written to: {OUTPUT_FILE_PATH}" in output_lines + assert os.path.exists(OUTPUT_FILE_PATH), f"Output file was not created at {OUTPUT_FILE_PATH}" + + os.remove(OUTPUT_FILE_PATH)