Tip: working effectively with cli

Recommendation

Pass a pre-built argument list to main(argv) instead of relying on sys.argv when you call the CLI programmatically.

main() accepts an explicit argv: list[str] | None parameter. When argv is None, it falls back to sys.argv, which makes behavior depend on the process environment. Passing a concrete list — for example, main(["query", "--question", "What is RAG?"]) — makes the call self-contained and predictable.

Why it matters: Scripts and tests that mutate sys.argv are fragile and interfere with each other; an explicit argv eliminates that coupling entirely.

Tradeoff: You need to reproduce the argument structure that build_parser() expects. Call build_parser().parse_args(your_list) first to validate your argument list before wiring it into main().

Source files

Tags: cli, query, corpus-info