A session can be configured with different files for credentials and queries.
This commit is contained in:
parent
d7f2e59f94
commit
91087cff7b
2 changed files with 36 additions and 4 deletions
11
cli.py
11
cli.py
|
|
@ -3,9 +3,12 @@ import json
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from query_performance_gauge import run_measuring_session
|
from query_performance_gauge import run_measuring_session
|
||||||
|
from utils import compose_config
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option("--config", required=True, type=click.File())
|
@click.option("--config", type=click.File())
|
||||||
def measure_performance(config):
|
@click.option("--credentials", type=click.File())
|
||||||
run_measuring_session(json.load(config))
|
@click.option("--queries", type=click.File())
|
||||||
|
def measure_performance(config, credentials, queries):
|
||||||
|
config = compose_config(config, credentials, queries)
|
||||||
|
run_measuring_session(config)
|
||||||
|
|
|
||||||
29
utils.py
Normal file
29
utils.py
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
from typing import Union
|
||||||
|
from io import TextIOWrapper
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
def compose_config(
|
||||||
|
config: Union[TextIOWrapper, None],
|
||||||
|
credentials: Union[TextIOWrapper, None],
|
||||||
|
queries: Union[TextIOWrapper, None],
|
||||||
|
) -> dict:
|
||||||
|
"""
|
||||||
|
Receive the CLI arguments and compose a session config.
|
||||||
|
|
||||||
|
:param config: file pointer to a full config file.
|
||||||
|
:param credentials: file pointer to a credentials file.
|
||||||
|
:param queries: file pointer to a queries file.
|
||||||
|
:return: a dict with the composed configuration.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if config is not None:
|
||||||
|
return json.load(config)
|
||||||
|
|
||||||
|
if credentials is None or queries is None:
|
||||||
|
raise ValueError(
|
||||||
|
"You need to provide both --credentials and --queries arguments."
|
||||||
|
)
|
||||||
|
|
||||||
|
# Merge both into one dict so it follows the same structure as a full config file
|
||||||
|
return {**json.load(credentials), **json.load(queries)}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue