mirror of
https://github.com/codex-storage/bittorrent-benchmarks.git
synced 2025-01-10 03:15:48 +00:00
move cli config parameter to before subcommand
This commit is contained in:
parent
3a319aa823
commit
3e1eee7870
@ -29,24 +29,24 @@ def _parse_config(config: Path):
|
||||
|
||||
|
||||
@app.command()
|
||||
def list(config: Path):
|
||||
def list(ctx: typer.Context):
|
||||
"""
|
||||
Lists the experiments available in CONFIG.
|
||||
"""
|
||||
experiments = _parse_config(config)
|
||||
print(f'Available experiments in {config}:')
|
||||
experiments = ctx.obj
|
||||
print(f'Available experiments are:')
|
||||
for experiment in experiments.keys():
|
||||
print(f' - {experiment}')
|
||||
|
||||
|
||||
@app.command()
|
||||
def run(config: Path, experiment: str):
|
||||
def run(ctx: typer.Context, experiment: str):
|
||||
"""
|
||||
Runs the experiment with name EXPERIMENT.
|
||||
"""
|
||||
experiments = _parse_config(config)
|
||||
experiments = ctx.obj
|
||||
if experiment not in experiments:
|
||||
print(f'Experiment {experiment} not found in {config}.')
|
||||
print(f'Experiment {experiment} not found.')
|
||||
sys.exit(-1)
|
||||
experiments[experiment].build().run()
|
||||
|
||||
@ -60,10 +60,14 @@ def _init_logging():
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
@app.callback()
|
||||
def main(ctx: typer.Context, config: Path):
|
||||
if ctx.resilient_parsing:
|
||||
return
|
||||
|
||||
ctx.obj = _parse_config(config)
|
||||
_init_logging()
|
||||
app()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
app()
|
||||
|
@ -11,5 +11,5 @@ RUN poetry install --no-root
|
||||
COPY . .
|
||||
RUN poetry install
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/bittorrent-benchmarks", "run", "/opt/bittorrent-benchmarks/experiments.yaml"]
|
||||
ENTRYPOINT ["/usr/local/bin/bittorrent-benchmarks", "/opt/bittorrent-benchmarks/experiments.yaml"]
|
||||
|
@ -33,4 +33,4 @@ requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
||||
[tool.poetry.scripts]
|
||||
bittorrent-benchmarks = "benchmarks.cli:main"
|
||||
bittorrent-benchmarks = "benchmarks.cli:app"
|
Loading…
x
Reference in New Issue
Block a user