53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
import os.path
|
|
|
|
import click
|
|
|
|
from jeeves.cli.echo import info, error, title, success
|
|
from jeeves.core.parsers import FlowParser
|
|
from jeeves.core.executor import Executor
|
|
|
|
|
|
@click.group()
|
|
def main():
|
|
pass
|
|
|
|
|
|
@main.command()
|
|
@click.argument("defintinion_file", type=click.File())
|
|
@click.option(
|
|
"--output",
|
|
"print_output",
|
|
is_flag=True,
|
|
default=False,
|
|
help="Display output for flow",
|
|
)
|
|
def execute(defintinion_file, print_output):
|
|
extension = os.path.splitext(defintinion_file.name)[1][1:]
|
|
|
|
if not hasattr(FlowParser, f"from_{extension}"):
|
|
error(f"Extension {extension} is not supported")
|
|
exit(1)
|
|
|
|
info(f"Running flow from {defintinion_file.name}")
|
|
|
|
flow = getattr(FlowParser, f"from_{extension}")(defintinion_file.read())
|
|
|
|
title(f"Running flow: {flow.name}")
|
|
executor = Executor(flow)
|
|
|
|
for n, step in enumerate(executor.steps, start=1):
|
|
click.echo(
|
|
f" ** Running step [{n}/{executor.step_count}]: {step.task.name}\r",
|
|
nl=False,
|
|
)
|
|
result = executor.execute_step(step)
|
|
if not result.success:
|
|
error(f"Executing step [{n}/{executor.step_count}]: {step.task.name}")
|
|
break
|
|
else:
|
|
success(f"Running step [{n}/{executor.step_count}]: {step.task.name}")
|
|
|
|
if print_output:
|
|
title("Full output:")
|
|
click.echo("\n".join(executor._execution.output))
|