#!/usr/bin/env python3
"""Download or refresh author BibTeX from INSPIRE-HEP for all authors in authors.txt.\n
Reads INSPIRE author IDs from the ``authors.txt`` file in the repository root
and fetches their publication BibTeX data from INSPIRE-HEP.  Downloads BibTeX
for authors that don't yet have a ``.bib`` file in ``authors/``, and refreshes
existing files when the paper count has changed on INSPIRE-HEP.\n
After processing individual authors, each author's ``.bib``, ``.md``, and
``.html`` files are updated in the ``authors/`` folder.\n
Options:
    --force   Re-download even if the paper count has not changed,
              otherwise only download when the count differs or the file
              is missing.\n
Usage:
    python scripts/refresh_all_author_bibs.py
    python scripts/refresh_all_author_bibs.py --force
"""

import argparse
import os
import sys

sys.path.insert(0, os.path.dirname(__file__))

from action_lib import sync_all_author_bibs

def main() -> None:
    """Parse CLI arguments and refresh author BibTeX for all authors."""
    parser = argparse.ArgumentParser(
        description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
    )
    parser.add_argument(
        "--force",
        action="store_true",
        help="Re-download even if the paper count has not changed",
    )
    args = parser.parse_args()
    #
    sync_all_author_bibs(args.force)

if __name__ == "__main__":
    main()
