|
1 | 1 | #!/usr/bin/env python3 |
2 | | -"""Universal CLI Help Crawler - OpenAPI for CLIs. |
| 2 | +"""Legacy compatibility script for ``cli-crawler``. |
3 | 3 |
|
4 | | -Crawls CLI --help outputs and generates structured JSON maps |
5 | | -that AI agents can use for precise command reasoning. |
6 | | -""" |
7 | | - |
8 | | -from __future__ import annotations |
9 | | - |
10 | | -import argparse |
11 | | -import logging |
12 | | -import sys |
13 | | -from pathlib import Path |
14 | | - |
15 | | -from crawler.config import CLIConfig, CrawlerConfig, load_config |
16 | | -from crawler.pipeline import crawl_all, crawl_cli |
17 | | - |
18 | | - |
19 | | -def main() -> None: |
20 | | - parser = argparse.ArgumentParser( |
21 | | - description="Crawl CLI --help outputs and generate structured JSON maps", |
22 | | - epilog="Examples:\n" |
23 | | - " python cli_crawler.py git -o output/git.json\n" |
24 | | - " python cli_crawler.py --config config.yaml --all\n" |
25 | | - " python cli_crawler.py docker -v --include-raw\n", |
26 | | - formatter_class=argparse.RawDescriptionHelpFormatter, |
27 | | - ) |
28 | | - parser.add_argument("cli", nargs="?", help="CLI to crawl (e.g., git, docker)") |
29 | | - parser.add_argument("--config", "-c", type=Path, help="Path to config YAML") |
30 | | - parser.add_argument("--output", "-o", type=Path, help="Output file path") |
31 | | - parser.add_argument( |
32 | | - "--output-dir", |
33 | | - type=Path, |
34 | | - default=Path("./output"), |
35 | | - help="Output directory (default: ./output)", |
36 | | - ) |
37 | | - parser.add_argument("--all", action="store_true", help="Crawl all CLIs in config") |
38 | | - parser.add_argument( |
39 | | - "--include-raw", action="store_true", help="Include raw help text in main JSON" |
40 | | - ) |
41 | | - parser.add_argument("--verbose", "-v", action="store_true", help="Verbose logging") |
42 | | - parser.add_argument("--strict", action="store_true", help="Fail on first parse error") |
43 | | - parser.add_argument("--max-depth", type=int, help="Override max recursion depth") |
44 | | - parser.add_argument("--timeout", type=int, help="Override timeout per command (seconds)") |
45 | | - parser.add_argument("--list", action="store_true", help="List configured CLIs and exit") |
46 | | - |
47 | | - args = parser.parse_args() |
48 | | - |
49 | | - # Configure logging |
50 | | - logging.basicConfig( |
51 | | - level=logging.DEBUG if args.verbose else logging.INFO, |
52 | | - format="%(asctime)s [%(levelname)s] %(name)s: %(message)s", |
53 | | - datefmt="%H:%M:%S", |
54 | | - ) |
| 4 | +Prefer invoking the canonical command directly: |
55 | 5 |
|
56 | | - # Load config |
57 | | - config: CrawlerConfig |
58 | | - if args.config and args.config.exists(): |
59 | | - config = load_config(str(args.config)) |
60 | | - else: |
61 | | - config = CrawlerConfig() |
62 | | - |
63 | | - # List mode |
64 | | - if args.list: |
65 | | - if not config.clis: |
66 | | - print("No CLIs configured. Use --config to specify a config file.") |
67 | | - else: |
68 | | - print(f"Configured CLIs ({len(config.clis)}):") |
69 | | - for name, cfg in sorted(config.clis.items()): |
70 | | - group = f" [{cfg.group}]" if cfg.group else "" |
71 | | - env = f" (env: {cfg.environment})" if cfg.environment != "wsl" else "" |
72 | | - print(f" {name}{group}{env}") |
73 | | - return |
74 | | - |
75 | | - # Crawl all CLIs |
76 | | - if args.all: |
77 | | - if not config.clis: |
78 | | - print("No CLIs configured. Use --config to specify a config file.") |
79 | | - sys.exit(1) |
80 | | - crawl_all(config, args.output_dir, args.include_raw, args.strict) |
81 | | - return |
82 | | - |
83 | | - # Crawl single CLI |
84 | | - if args.cli: |
85 | | - cli_config = config.clis.get(args.cli, CLIConfig(name=args.cli)) |
86 | | - |
87 | | - # Apply CLI arg overrides |
88 | | - if args.max_depth is not None: |
89 | | - cli_config.max_depth = args.max_depth |
90 | | - if args.timeout is not None: |
91 | | - cli_config.timeout = args.timeout |
92 | | - |
93 | | - output = args.output or args.output_dir / f"{args.cli}.json" |
94 | | - crawl_cli(args.cli, cli_config, output, args.include_raw, args.strict) |
95 | | - return |
96 | | - |
97 | | - # No action specified |
98 | | - parser.print_help() |
99 | | - sys.exit(1) |
| 6 | + cli-crawler <cli_name> [options] |
| 7 | +""" |
100 | 8 |
|
| 9 | +from crawler.cli_crawler import main |
101 | 10 |
|
102 | 11 | if __name__ == "__main__": |
103 | 12 | main() |
0 commit comments