#!/usr/bin/env python3
"""Download references for an arXiv paper from INSPIRE-HEP.\n
Given an arXiv ID (e.g. 2604.20797 or hep-ph/0603175), resolves the paper on
INSPIRE-HEP and saves references to {id}_references.bib, {id}_references.md,
and {id}_references.html in the appropriate YYYY/ARXIV_ID/ folder.\n
Usage:
    python scripts/download_inspire_references.py 2604.20797
    python scripts/download_inspire_references.py hep-ph/0603175
    python scripts/download_inspire_references.py 2604.20797 2604.12345
"""

import argparse
import os
import sys

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

from action_lib import download_and_save_references
from inspire_lib import log_to_stderr

def main() -> None:
    """Parse CLI arguments and download references for the given arXiv IDs."""
    parser = argparse.ArgumentParser(
        description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
    )
    parser.add_argument(
        "arxiv_ids",
        nargs="+",
        help="arXiv paper ID(s), e.g. 2604.20797 or hep-ph/0603175",
    )
    args = parser.parse_args()
    #
    for arxiv_id in args.arxiv_ids:
        download_and_save_references(arxiv_id)
    #
    log_to_stderr("All done.")

if __name__ == "__main__":
    main()
