MCPcopy Create free account
hub / github.com/CodeGraphContext/CodeGraphContext / index

Function index

src/codegraphcontext/cli/main.py:1300–1352  ·  view source on GitHub ↗

Indexes a directory or file by adding it to the code graph. If no path is provided, it indexes the current directory. Use --force to delete the existing index and rebuild from scratch. Use --summarize to display a summary after indexing.

(
    path: Optional[str] = typer.Argument(None, help="Path to the directory or file to index. Defaults to the current directory."),
    force: bool = typer.Option(False, "--force", "-f", help="Force re-index (delete existing and rebuild)"),
    context: Optional[str] = typer.Option(None, "--context", "-c", help="Specific context to use (overrides mode/default)"),
    summarize: bool = typer.Option(False, "--summarize", "-s", help="Show a summary of the indexed codebase after indexing"),
)

Source from the content-addressed store, hash-verified

1298@app.command()
1299@app.command()
1300def index(
1301 path: Optional[str] = typer.Argument(None, help="Path to the directory or file to index. Defaults to the current directory."),
1302 force: bool = typer.Option(False, "--force", "-f", help="Force re-index (delete existing and rebuild)"),
1303 context: Optional[str] = typer.Option(None, "--context", "-c", help="Specific context to use (overrides mode/default)"),
1304 summarize: bool = typer.Option(False, "--summarize", "-s", help="Show a summary of the indexed codebase after indexing"),
1305):
1306 """
1307 Indexes a directory or file by adding it to the code graph.
1308 If no path is provided, it indexes the current directory.
1309
1310 Use --force to delete the existing index and rebuild from scratch.
1311 Use --summarize to display a summary after indexing.
1312 """
1313 _load_credentials()
1314 if path is None:
1315 path = str(Path.cwd())
1316
1317 try:
1318 if force:
1319 console.print("[yellow]Force re-indexing (--force flag detected)[/yellow]")
1320 reindex_helper(path, context)
1321 else:
1322 index_helper(path, context)
1323 except Exception as e:
1324 if str(e):
1325 console.print(f"[red]An error occurred during indexing: {e}[/red]")
1326
1327 if summarize:
1328 import os
1329
1330 py_files = []
1331 for root, dirs, files in os.walk(path):
1332 dirs[:] = [d for d in dirs if not d.startswith('.') and d not in ['venv', '__pycache__', 'node_modules']]
1333 for file in files:
1334 if file.endswith('.py'):
1335 py_files.append(os.path.join(root, file))
1336
1337 total_lines = 0
1338 for f in py_files:
1339 try:
1340 with open(f, 'r', encoding='utf-8', errors='ignore') as fp:
1341 total_lines += len(fp.readlines())
1342 except:
1343 pass
1344
1345 console.print("\n[bold cyan]📊 Codebase Summary:[/bold cyan]")
1346 console.print(f" • Path indexed : [green]{path}[/green]")
1347 console.print(f" • Python files : [yellow]{len(py_files)}[/yellow]")
1348 console.print(f" • Total lines : [yellow]{total_lines}[/yellow]")
1349 console.print(f"\n • Run [bold]cgc analyze complexity[/bold] to find complex functions")
1350 console.print(f" • Run [bold]cgc analyze dead-code[/bold] to find unused code")
1351 console.print(f" • Run [bold]cgc list[/bold] to see all indexed repositories")
1352 console.print("\n[dim]Tip: Use --summarize anytime after indexing to see this.[/dim]")
1353
1354@app.command()
1355def update(

Callers 1

index_abbrevFunction · 0.85

Calls 6

_load_credentialsFunction · 0.85
reindex_helperFunction · 0.85
index_helperFunction · 0.85
printMethod · 0.80
appendMethod · 0.65
walkMethod · 0.45

Tested by

no test coverage detected