From a2c405d951218295ab6f689347561053c3443021 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Mon, 20 Dec 2021 12:32:39 -0500 Subject: [PATCH] Generalize CLI --- src/chembl_downloader/cli.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/chembl_downloader/cli.py b/src/chembl_downloader/cli.py index 9375f56..58e5b23 100644 --- a/src/chembl_downloader/cli.py +++ b/src/chembl_downloader/cli.py @@ -2,7 +2,6 @@ """CLI for :mod:`chembl_downloader`.""" -import sys from typing import Optional import click @@ -15,17 +14,27 @@ "main", ] +version_option = click.option("--version", help="The ChEMBL version to use.") -@click.command() -@verbose_option -@click.option("--version") -@click.option("--test", is_flag=True, help="Run a test query") -def main(version: Optional[str], test: bool): + +@click.group() +def main(): """Test the connection.""" - if not test: - click.echo(download_extract_sqlite(version=version)) - sys.exit(0) + +@main.command() +@version_option +@verbose_option +def download(version: Optional[str]): + """Download the data.""" + click.echo(download_extract_sqlite(version=version)) + + +@main.command() +@version_option +@verbose_option +def test(version: Optional[str]): + """Run test queries.""" click.secho("ID to Name Query\n", fg="green") df = query(ID_NAME_QUERY + "\nLIMIT 5", version=version) click.echo(df.to_markdown(index=False))