about summary refs log tree commit diff
path: root/scripts/cli/options.py
blob: 67f35dc00cdf51483c9ea32619b0e725291ed326 (plain)
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
43
44
45
46
"""General options to be added to CLI scripts."""
from argparse import ArgumentParser


def add_logging(parser: ArgumentParser) -> ArgumentParser:
    """Add optional log-level option"""
    loglevels = ("debug", "info", "warning", "error", "critical")
    parser.add_argument(
        "--log_level",
        "--log-level",
        "--loglevel",
        metavar="LOG-LEVEL",
        type=str,
        default="INFO",
        choices=loglevels,
        help=(f"Controls the severity of events to log. Valid values are: " +
              ", ".join(f"'{level}'" for level in loglevels)))
    return parser


def add_mariadb_uri(parser: ArgumentParser) -> ArgumentParser:
    """Add the MySQL/MariaDB URI argument."""
    parser.add_argument("db_uri",
                        metavar="DB-URI",
                        type=str,
                        help="MariaDB/MySQL connection URL")
    return parser


def add_species_id(parser: ArgumentParser) -> ArgumentParser:
    """Add species-id as a mandatory argument."""
    parser.add_argument("species_id",
                        metavar="SPECIES-ID",
                        type=int,
                        help="The species to operate on.")
    return parser


def add_population_id(parser: ArgumentParser) -> ArgumentParser:
    """Add population-id as a mandatory argument."""
    parser = add_species_id(parser)
    parser.add_argument("population_id",
                        metavar="POPULATION-ID",
                        type=int,
                        help="The ID for the population to operate on.")
    return parser