Skip to content

Commit

Permalink
🚸 use env vars as options. #17
Browse files Browse the repository at this point in the history
  • Loading branch information
perillaroc committed May 12, 2022
1 parent e7b9a93 commit ca5a845
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions takler/client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

TAKLER_HOST = "TAKLER_HOST"
TAKLER_PORT = "TAKLER_PORT"
TAKLER_NAME = "TAKLER_NAME"


app = typer.Typer()
Expand All @@ -16,12 +17,13 @@
@app.command()
def init(
task_id: str = typer.Option(...),
node_path: str = typer.Option(...),
node_path: str = typer.Option(None, help="node path"),
host: str = typer.Option(None, help="takler service host"),
port: int = typer.Option(None, help="takler service port"),
):
host = get_host(host)
port = get_port(port)
node_path = get_node_path(node_path)
client = TaklerServiceClient(host=host, port=port)
client.start()
client.run_command_init(node_path=node_path, task_id=task_id)
Expand All @@ -30,12 +32,13 @@ def init(

@app.command()
def complete(
node_path: str = typer.Option(...),
node_path: str = typer.Option(None, help="node path"),
host: str = typer.Option(None, help="takler service host"),
port: int = typer.Option(None, help="takler service port"),
):
host = get_host(host)
port = get_port(port)
node_path = get_node_path(node_path)
client = TaklerServiceClient(host=host, port=port)
client.start()
client.run_command_complete(node_path=node_path)
Expand All @@ -44,13 +47,14 @@ def complete(

@app.command()
def abort(
node_path: str = typer.Option(...),
node_path: str = typer.Option(None, help="node path"),
host: str = typer.Option(None, help="takler service host"),
port: int = typer.Option(None, help="takler service port"),
reason: str = typer.Option("", help="abort reason")
):
host = get_host(host)
port = get_port(port)
node_path = get_node_path(node_path)
client = TaklerServiceClient(host=host, port=port)
client.start()
client.run_command_abort(node_path=node_path, reason=reason)
Expand All @@ -59,13 +63,14 @@ def abort(

@app.command()
def event(
node_path: str = typer.Option(...),
node_path: str = typer.Option(None, help="node path"),
host: str = typer.Option(None, help="takler service host"),
port: int = typer.Option(None, help="takler service port"),
event_name: str = typer.Option(..., help="event name"),
):
host = get_host(host)
port = get_port(port)
node_path = get_node_path(node_path)
client = TaklerServiceClient(host=host, port=port)
client.start()
client.run_command_event(node_path=node_path, event_name=event_name)
Expand All @@ -74,14 +79,15 @@ def event(

@app.command()
def meter(
node_path: str = typer.Option(...),
node_path: str = typer.Option(None, help="node path"),
host: str = typer.Option(None, help="takler service host"),
port: int = typer.Option(None, help="takler service port"),
meter_name: str = typer.Option(..., help="meter name"),
meter_value: str = typer.Option(..., help="meter value"),
):
host = get_host(host)
port = get_port(port)
node_path = get_node_path(node_path)
client = TaklerServiceClient(host=host, port=port)
client.start()
client.run_command_meter(node_path=node_path, meter_name=meter_name, meter_value=meter_value)
Expand All @@ -92,12 +98,13 @@ def meter(

@app.command()
def requeue(
node_path: str = typer.Option(...),
node_path: str = typer.Option(None, help="node path"),
host: str = typer.Option(None, help="takler service host"),
port: int = typer.Option(None, help="takler service port"),
):
host = get_host(host)
port = get_port(port)
node_path = get_node_path(node_path)
client = TaklerServiceClient(host=host, port=port)
client.start()
client.run_command_requeue(node_path=node_path)
Expand All @@ -120,6 +127,9 @@ def show(
client.shutdown()


# ----------------------------


def get_host(host: Optional[str] = None) -> Optional[str]:
if host is not None:
return host
Expand All @@ -134,3 +144,11 @@ def get_port(port: Optional[int] = None) -> Optional[int]:
if TAKLER_PORT in os.environ:
return int(os.environ[TAKLER_PORT])
return None


def get_node_path(node_path: Optional[str] = None) -> Optional[str]:
if node_path is not None:
return node_path
if TAKLER_NAME in os.environ:
return os.environ[TAKLER_NAME]
return None

0 comments on commit ca5a845

Please sign in to comment.