feat: create libretime_shared package (#1349)
* feat: create libretime_shared package - We don't use pydantic.BaseSettings because of some incompatble loading behavior. * fix: whitelist pydantic in pylintrc * docs: update to new BaseConfig behavior * docs: change confusing config filepath
This commit is contained in:
parent
ba8b51af76
commit
3a615cafa0
13 changed files with 568 additions and 0 deletions
65
shared/libretime_shared/cli.py
Normal file
65
shared/libretime_shared/cli.py
Normal file
|
@ -0,0 +1,65 @@
|
|||
from typing import Callable
|
||||
|
||||
import click
|
||||
|
||||
from .config import DEFAULT_ENV_PREFIX
|
||||
|
||||
|
||||
def cli_logging_options(func: Callable) -> Callable:
|
||||
"""
|
||||
Decorator function to add logging options to a click application.
|
||||
|
||||
This decorator add the following arguments:
|
||||
- verbosity: int
|
||||
- log_filepath: Path
|
||||
"""
|
||||
func = click.option(
|
||||
"-v",
|
||||
"--verbose",
|
||||
"verbosity",
|
||||
envvar=f"{DEFAULT_ENV_PREFIX}_VERBOSITY",
|
||||
count=True,
|
||||
default=0,
|
||||
help="Increase logging verbosity (use -vvv to debug).",
|
||||
)(func)
|
||||
|
||||
func = click.option(
|
||||
"-q",
|
||||
"--quiet",
|
||||
"verbosity",
|
||||
is_flag=True,
|
||||
flag_value=-1,
|
||||
help="Decrease logging verbosity.",
|
||||
)(func)
|
||||
|
||||
func = click.option(
|
||||
"--log-filepath",
|
||||
"log_filepath",
|
||||
envvar=f"{DEFAULT_ENV_PREFIX}_LOG_FILEPATH",
|
||||
type=click.Path(),
|
||||
help="Path to the logging file.",
|
||||
default=None,
|
||||
)(func)
|
||||
|
||||
return func
|
||||
|
||||
|
||||
def cli_config_options(func: Callable) -> Callable:
|
||||
"""
|
||||
Decorator function to add config file options to a click application.
|
||||
|
||||
This decorator add the following arguments:
|
||||
- config_filepath: Path
|
||||
"""
|
||||
|
||||
func = click.option(
|
||||
"--c",
|
||||
"--config",
|
||||
"config_filepath",
|
||||
envvar=f"{DEFAULT_ENV_PREFIX}_CONFIG_FILEPATH",
|
||||
type=click.Path(),
|
||||
help="Path to the config file.",
|
||||
default=None,
|
||||
)(func)
|
||||
|
||||
return func
|
Loading…
Add table
Add a link
Reference in a new issue