Skip to content

Commit

Permalink
Generalize CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Dec 20, 2021
1 parent 56604e8 commit a2c405d
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/chembl_downloader/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

"""CLI for :mod:`chembl_downloader`."""

import sys
from typing import Optional

import click
Expand All @@ -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))
Expand Down

0 comments on commit a2c405d

Please sign in to comment.