(argv: Optional[List[str]] = None)
| 482 | |
| 483 | |
| 484 | def main(argv: Optional[List[str]] = None) -> int: |
| 485 | args = parse_args(argv) |
| 486 | tiny_path = Path(args.tiny) |
| 487 | if not tiny_path.exists(): |
| 488 | print(f"tiny file not found: {tiny_path}", file=sys.stderr) |
| 489 | return 1 |
| 490 | |
| 491 | if not args.no_git_pull: |
| 492 | repo_root = detect_repo_root(tiny_path.parent.resolve()) |
| 493 | if repo_root is None: |
| 494 | print("Not inside a git repository, cannot run git pull --ff-only.", file=sys.stderr) |
| 495 | return 1 |
| 496 | ok, output = git_pull_ff_only(repo_root) |
| 497 | if not ok: |
| 498 | print("git pull --ff-only failed; aborting to avoid drift.", file=sys.stderr) |
| 499 | if output: |
| 500 | print(output, file=sys.stderr) |
| 501 | return 1 |
| 502 | if output: |
| 503 | print(output) |
| 504 | |
| 505 | feed_url = normalize_url(args.url or prompt_for_feed_url()) |
| 506 | if not is_http_url(feed_url): |
| 507 | print("Invalid RSS URL; must be http/https.", file=sys.stderr) |
| 508 | return 1 |
| 509 | |
| 510 | try: |
| 511 | metadata = fetch_feed_metadata(feed_url, timeout=args.timeout) |
| 512 | except ValueError as exc: |
| 513 | print(str(exc), file=sys.stderr) |
| 514 | return 1 |
| 515 | |
| 516 | tree = ET.parse(tiny_path) |
| 517 | body = get_body(tree, tiny_path) |
| 518 | categories = list_categories(body) |
| 519 | chosen_category = (args.category or "").strip() or prompt_for_category(categories) |
| 520 | |
| 521 | added, target_category, was_updated = add_feed_to_tree( |
| 522 | tree, chosen_category, metadata, update_if_exists=args.update |
| 523 | ) |
| 524 | if not added: |
| 525 | print(f"Feed already exists in category: {target_category}") |
| 526 | print(f"RSS: {metadata.xml_url}") |
| 527 | print("Use --update flag to update the existing feed.") |
| 528 | return 0 |
| 529 | |
| 530 | tiny_path.write_bytes(serialize_tree(tree)) |
| 531 | if was_updated: |
| 532 | print("Feed updated in tiny.opml successfully:") |
| 533 | else: |
| 534 | print("Feed added into tiny.opml successfully:") |
| 535 | print(f"- Category: {target_category}") |
| 536 | print(f"- Title: {metadata.title}") |
| 537 | print(f"- Site: {metadata.html_url}") |
| 538 | print(f"- RSS: {metadata.xml_url}") |
| 539 | return 0 |
| 540 | |
| 541 |
no test coverage detected