Skip to content

Commit 71b1167

Browse files
Refactor CLI to wrap async logic with a sync command function (#136)
- Change main() to a synchronous Click command - Introduce _async_main() for async ingest logic - Use asyncio.run(...) to properly await the async function
1 parent d721b00 commit 71b1167

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

src/gitingest/cli.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,51 @@
22

33
# pylint: disable=no-value-for-parameter
44

5+
import asyncio
6+
57
import click
68

79
from config import MAX_FILE_SIZE
810
from gitingest.repository_ingest import ingest
911

1012

1113
@click.command()
12-
@click.argument("source", type=str, required=True)
14+
@click.argument("source", type=str, default=".")
1315
@click.option("--output", "-o", default=None, help="Output file path (default: <repo_name>.txt in current directory)")
1416
@click.option("--max-size", "-s", default=MAX_FILE_SIZE, help="Maximum file size to process in bytes")
1517
@click.option("--exclude-pattern", "-e", multiple=True, help="Patterns to exclude")
1618
@click.option("--include-pattern", "-i", multiple=True, help="Patterns to include")
17-
async def main(
19+
def main(
20+
source: str,
21+
output: str | None,
22+
max_size: int,
23+
exclude_pattern: tuple[str, ...],
24+
include_pattern: tuple[str, ...],
25+
):
26+
"""
27+
Main entry point for the CLI. This function is called when the CLI is run as a script.
28+
29+
It calls the async main function to run the command.
30+
31+
Parameters
32+
----------
33+
source : str
34+
The source directory or repository to analyze.
35+
output : str | None
36+
The path where the output file will be written. If not specified, the output will be written
37+
to a file named `<repo_name>.txt` in the current directory.
38+
max_size : int
39+
The maximum file size to process, in bytes. Files larger than this size will be ignored.
40+
exclude_pattern : tuple[str, ...]
41+
A tuple of patterns to exclude during the analysis. Files matching these patterns will be ignored.
42+
include_pattern : tuple[str, ...]
43+
A tuple of patterns to include during the analysis. Only files matching these patterns will be processed.
44+
"""
45+
# Main entry point for the CLI. This function is called when the CLI is run as a script.
46+
asyncio.run(_async_main(source, output, max_size, exclude_pattern, include_pattern))
47+
48+
49+
async def _async_main(
1850
source: str,
1951
output: str | None,
2052
max_size: int,
@@ -24,9 +56,8 @@ async def main(
2456
"""
2557
Analyze a directory or repository and create a text dump of its contents.
2658
27-
This command analyzes the contents of a specified source directory or repository,
28-
applies custom include and exclude patterns, and generates a text summary of the analysis
29-
which is then written to an output file.
59+
This command analyzes the contents of a specified source directory or repository, applies custom include and
60+
exclude patterns, and generates a text summary of the analysis which is then written to an output file.
3061
3162
Parameters
3263
----------

0 commit comments

Comments
 (0)