|
| 1 | +import argparse |
| 2 | +import sys |
| 3 | + |
1 | 4 | from sort_table import sort_table |
2 | | -from check_table import check_table |
| 5 | +from check_table import check_table_consistency as check_table_links |
3 | 6 | from check_repo_link_vs_user_link_inconsistencies import check_table_consistency |
| 7 | +from fix_serials import fix_serials |
| 8 | + |
| 9 | + |
| 10 | +def cmd_sort(args): |
| 11 | + """Sort the README table by GitHub star count.""" |
| 12 | + sort_table(args.file) |
| 13 | + |
| 14 | + |
| 15 | +def cmd_check(args): |
| 16 | + """Run consistency checks on the README table.""" |
| 17 | + file_path = args.file |
| 18 | + check_table_links(file_path) |
| 19 | + check_table_consistency(file_path) |
| 20 | + |
| 21 | + |
| 22 | +def cmd_fix_serials(args): |
| 23 | + """Re-number table rows sequentially starting from 1.""" |
| 24 | + fix_serials(args.file) |
| 25 | + print(f"Serial numbers fixed in {args.file}") |
| 26 | + |
| 27 | + |
| 28 | +def cmd_all(args): |
| 29 | + """Run the full pipeline: sort β check β fix serials.""" |
| 30 | + cmd_sort(args) |
| 31 | + cmd_fix_serials(args) |
| 32 | + cmd_check(args) |
| 33 | + |
4 | 34 |
|
5 | 35 |
|
6 | 36 | def main(): |
7 | | - print("Hello from top-ai-repos!") |
| 37 | + parser = argparse.ArgumentParser( |
| 38 | + prog="top-ai-repos", |
| 39 | + description="Maintain the Top-AI-repos curated list.", |
| 40 | + ) |
| 41 | + parser.add_argument( |
| 42 | + "-f", "--file", |
| 43 | + default="README.md", |
| 44 | + help="Path to the README file (default: README.md)", |
| 45 | + ) |
| 46 | + |
| 47 | + subparsers = parser.add_subparsers(dest="command") |
| 48 | + |
| 49 | + subparsers.add_parser("sort", help="Sort table by star count") |
| 50 | + subparsers.add_parser("check", help="Run consistency checks") |
| 51 | + subparsers.add_parser("fix-serials", help="Fix row serial numbers") |
| 52 | + subparsers.add_parser("all", help="Run full pipeline: sort, fix-serials, check") |
| 53 | + |
| 54 | + args = parser.parse_args() |
| 55 | + |
| 56 | + commands = { |
| 57 | + "sort": cmd_sort, |
| 58 | + "check": cmd_check, |
| 59 | + "fix-serials": cmd_fix_serials, |
| 60 | + "all": cmd_all, |
| 61 | + } |
| 62 | + |
| 63 | + if args.command is None: |
| 64 | + parser.print_help() |
| 65 | + sys.exit(0) |
| 66 | + |
| 67 | + commands[args.command](args) |
8 | 68 |
|
9 | 69 |
|
10 | 70 | if __name__ == "__main__": |
|
0 commit comments