From 075072f7dacd0a3b0101fc644f983e9f297d07dd Mon Sep 17 00:00:00 2001 From: Excel Chukwu Date: Wed, 7 Aug 2024 22:45:17 +0200 Subject: [PATCH] Feat: Allow user to specify download directory when CLI 'download' command 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 --- arxiv_retriever/cli.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arxiv_retriever/cli.py b/arxiv_retriever/cli.py index 6b9d0a4..24d7c58 100644 --- a/arxiv_retriever/cli.py +++ b/arxiv_retriever/cli.py @@ -1,5 +1,6 @@ from typing import List import sys +import os from importlib.metadata import version as vsn from typing_extensions import Annotated @@ -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). @@ -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}")