-
Notifications
You must be signed in to change notification settings - Fork 28
/
cli.py
42 lines (28 loc) · 960 Bytes
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import logging
from typing import Union
import click
from stactools.cli import registry
def setup_logging(level: Union[str, int]) -> None:
logger = logging.getLogger("stactools")
logger.setLevel(level)
ch = logging.StreamHandler()
ch.setLevel(level)
formatter = logging.Formatter("%(message)s")
ch.setFormatter(formatter)
logger.addHandler(ch)
@click.group()
@click.option("-v", "--verbose", help=("Use verbose mode"), is_flag=True)
@click.option("-q", "--quiet", help=("Use quiet mode (no output)"), is_flag=True)
def cli(verbose: bool, quiet: bool) -> None:
logging_level = logging.INFO
if verbose:
logging_level = logging.DEBUG
if quiet:
logging_level = logging.ERROR
setup_logging(logging_level)
for create_subcommand in registry.get_create_subcommand_functions():
create_subcommand(cli)
def run_cli() -> None:
cli(prog_name="stac")
if __name__ == "__main__":
run_cli()