Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 55 additions & 11 deletions src/gitingest/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ class _CLIArgs(TypedDict):

@click.command()
@click.argument("source", type=str, default=".")
@click.option(
"--output",
"-o",
default=None,
help="Output file path (default: digest.txt in current directory). Use '-' for stdout.",
)
@click.option(
"--max-size",
"-s",
Expand Down Expand Up @@ -57,14 +63,52 @@ class _CLIArgs(TypedDict):
"If omitted, the CLI will look for the GITHUB_TOKEN environment variable."
),
)
@click.option(
"--output",
"-o",
default=None,
help="Write to PATH (or '-' for stdout, default: <repo>.txt).",
)
def main(**cli_kwargs: Unpack[_CLIArgs]) -> None:
"""Run the CLI entry point to analyze a repo / directory and dump its contents."""
"""
Main entry point for the CLI. This function is called when the CLI is run as a script.

It calls the async main function to run the command.

Parameters
----------
source : str
A directory path or a Git repository URL.
output : str, optional
The path where the output file will be written. If not specified, the output will be written
to a file named `digest.txt` in the current directory. Use '-' to output to stdout.
max_size : int
Maximum file size (in bytes) to consider.
exclude_pattern : Tuple[str, ...]
Glob patterns for pruning the file set.
include_pattern : Tuple[str, ...]
Glob patterns for including files in the output.
branch : str, optional
Specific branch to ingest (defaults to the repository's default).
include_gitignored : bool
If provided, include files normally ignored by .gitignore.
token: str, optional
GitHub personal-access token (PAT). Needed when *source* refers to a
**private** repository. Can also be set via the ``GITHUB_TOKEN`` env var.

Examples
--------
Basic usage:
$ gitingest .
$ gitingest /path/to/repo
$ gitingest https://github.com/user/repo

Output to stdout:
$ gitingest . -o -
$ gitingest https://github.com/user/repo --output -

With filtering:
$ gitingest . -i "*.py" -e "*.log"
$ gitingest . --include-pattern "*.js" --exclude-pattern "node_modules/*"

Private repositories:
$ gitingest https://github.com/user/private-repo -t ghp_token
$ GITHUB_TOKEN=ghp_token gitingest https://github.com/user/private-repo
"""
asyncio.run(_async_main(**cli_kwargs))


Expand All @@ -88,7 +132,7 @@ async def _async_main(
Parameters
----------
source : str
Directory path or Git repository URL.
A directory path or a Git repository URL.
max_size : int
Maximum file size in bytes to ingest (default: 10 MB).
exclude_pattern : tuple[str, ...] | None
Expand All @@ -103,8 +147,8 @@ async def _async_main(
GitHub personal access token (PAT) for accessing private repositories.
Can also be set via the ``GITHUB_TOKEN`` environment variable.
output : str | None
Destination file path. If ``None``, the output is written to ``<repo_name>.txt`` in the current directory.
Use ``"-"`` to write to ``stdout``.
The path where the output file will be written. If not specified, the output will be written
to a file named `digest.txt` in the current directory. Use '-' to output to stdout.

Raises
------
Expand Down Expand Up @@ -151,4 +195,4 @@ async def _async_main(


if __name__ == "__main__":
main()
main()
4 changes: 2 additions & 2 deletions src/static/llm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ gitingest https://github.com/user/private-repo -t $GITHUB_TOKEN -o -
# Specific branch analysis (short flag)
gitingest https://github.com/user/repo -b main -o -

# Save to file (default: <repo_name>.txt in current directory)
# Save to file (default: digest.txt in current directory)
gitingest https://github.com/user/repo -o my_analysis.txt

# Ultra-concise example for small files only
gitingest https://github.com/user/repo -i "*.py" -s 51200 -o -
```

**Key Parameters for AI Agents**:
- `-o` / `--output`: Stream to STDOUT with `-` (default saves to `<repo_name>.txt`)
- `-o` / `--output`: Stream to STDOUT with `-` (default saves to `digest.txt`)
- `-s` / `--max-size`: Maximum file size in bytes to process (default: no limit)
- `-i` / `--include-pattern`: Include files matching Unix shell-style wildcards
- `-e` / `--exclude-pattern`: Exclude files matching Unix shell-style wildcards
Expand Down
Loading