Skip to content

Commit

Permalink
Feat: Allow user to specify download directory when CLI 'download' co…
Browse files Browse the repository at this point in the history
…mmand is invoked

- Use Typer to prompt user for download directory while showing default directory
- Expand user directory if used
- Add '--download-dir' and '-d' as alternative declarations for 'download_dir' option

Signed-off-by: Excel Chukwu <[email protected]>
  • Loading branch information
MimicTester1307 committed Aug 7, 2024
1 parent 77fc93f commit 075072f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions arxiv_retriever/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import List
import sys
import os
from importlib.metadata import version as vsn
from typing_extensions import Annotated

Expand Down Expand Up @@ -98,7 +99,7 @@ def search(
@app.command()
def download(
links: Annotated[List[str], typer.Argument(help="ArXiv links to download")],
download_dir: str = typer.Option("./axiv_downloads", help="Directory to download papers"),
download_dir: str = typer.Option("./arxiv_downloads", "--download-dir", "-d", help="Directory to download papers"),
):
"""
Download papers from ArXiv using their links (PDF or abstract links).
Expand All @@ -107,8 +108,10 @@ def download(
:param download_dir: Directory to download papers
:return: None
"""
typer.echo(f"Downloading papers from provided links...")
download_dir = typer.prompt(f"Enter download directory: ", default=download_dir)
download_dir = os.path.expanduser(download_dir) # expand user directory if used

typer.echo(f"Downloading papers from provided links...")
try:
trio.run(download_from_links, links, download_dir)
typer.echo(f"Download complete. Papers saved to {download_dir}")
Expand Down

0 comments on commit 075072f

Please sign in to comment.