Skip to content

Commit

Permalink
fix(cli): improved cli structure
Browse files Browse the repository at this point in the history
  • Loading branch information
shinybrar committed Jun 4, 2024
1 parent 4d90dbe commit 08ce5e3
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 40 deletions.
2 changes: 1 addition & 1 deletion workflow/cli/buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
)


@click.group(name="buckets", help="Manage workflow buckets.")
@click.group(name="buckets", help="Manage Workflow Buckets.")
def buckets():
"""Manage workflow pipelines."""
pass
Expand Down
2 changes: 1 addition & 1 deletion workflow/cli/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

@click.group(name="configs", help="Manage Workflow Configs. Version 2.")
def configs():
"""Manage workflow configs."""
"""Manage Workflow Configs."""
pass


Expand Down
14 changes: 12 additions & 2 deletions workflow/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Workflow command line interface."""

from typing import List

import click
from rich.console import Console

Expand All @@ -15,10 +17,18 @@
console = Console()


@click.group()
class OrderedCommands(click.Group):
"""Order Click Commands."""

def list_commands(self, ctx: click.Context) -> List[str]:
"""List Commands."""
return list(self.commands)


@click.group(cls=OrderedCommands)
def cli():
"""Workflow Command Line Interface."""
# ? Get workspace
# ? Get Workspace
message = get_active_workspace()
console.print(message)
pass
Expand Down
2 changes: 1 addition & 1 deletion workflow/cli/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

@click.group(name="pipelines", help="Manage Workflow Pipelines.")
def pipelines():
"""Manage workflow pipelines."""
"""Manage Workflow Pipelines."""
pass


Expand Down
4 changes: 2 additions & 2 deletions workflow/cli/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
yes_no_colors = {"yes": "green", "no": "red"}


@click.group(name="results", help="Manage workflow results.")
@click.group(name="results", help="Manage Workflow Results.")
def results():
"""Manage workflow results."""
"""Manage Workflow Results."""
pass


Expand Down
58 changes: 29 additions & 29 deletions workflow/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,8 @@
logger = get_logger("workflow.cli")


@click.command("run", short_help="Perform work.")
@click.argument("bucket", type=str, required=True)
@click.option(
"-f",
"--function",
type=str,
required=False,
default=None,
show_default=True,
help="Override work function to execute. e.g `workflow.tasks.example`.",
)
@click.option(
"-c",
"--command",
type=str,
required=False,
default=None,
show_default=True,
help="Override work command to execute. e.g `echo hello world`.",
)
@click.command("run", short_help="Fetch & Perform Work.")
@click.argument("buckets", type=str, required=True)
@click.option(
"-s",
"--site",
Expand All @@ -55,7 +37,7 @@
required=False,
default=None,
show_default=True,
help="filter work by tag, multiple values allowed.",
help="filter work by tag.",
)
@click.option(
"-p",
Expand All @@ -66,27 +48,46 @@
show_default=True,
help="filter work by parent.",
)
@click.option(
"-f",
"--function",
type=str,
required=False,
default=None,
show_default=True,
help="overload function to execute.",
)
@click.option(
"-c",
"--command",
type=str,
required=False,
default=None,
show_default=True,
help="overload command to execute.",
)
@click.option(
"--lives",
"-l",
type=int,
default=1,
default=-1,
show_default=True,
help="number of times to attempt work.",
help="count of work to perform.",
)
@click.option(
"--sleep",
type=int,
default=30,
show_default=True,
help="sleep time between attempts.",
help="sleep between work attempts.",
)
@click.option(
"-w",
"--workspace",
type=click.Path(exists=True, file_okay=True, dir_okay=False, readable=True),
default=DEFAULT_WORKSPACE_PATH,
show_default=True,
help="workspace config path.",
help="workspace config.",
)
@click.option(
"--log-level",
Expand All @@ -97,23 +98,22 @@
)
def run(
bucket: str,
function: str,
command: str,
site: str,
tag: Tuple[str],
parent: Optional[str],
function: str,
command: str,
lives: int,
sleep: int,
workspace: str,
log_level: str,
):
"""Perform work retrieved from the workflow buckets."""
"""Fetch & Perform Work."""
# Set logging level
logger.root.setLevel(log_level)
logger.root.handlers[0].setLevel(log_level)
config = reader.workspace(workspace)
baseurls = config.get("http", {}).get("baseurls", {})

buckets_url = baseurls.get("buckets", None)
loki_url = baseurls.get("loki", None)
products_url = baseurls.get("products", None)
Expand Down
2 changes: 1 addition & 1 deletion workflow/cli/schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

@click.group(name="schedules", help="Manage Workflow Schedules.")
def schedules():
"""Manage workflow Schedules."""
"""Manage Workflow Schedules."""
pass


Expand Down
11 changes: 8 additions & 3 deletions workflow/cli/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
modulestems = [space.stem for space in modulespaces.glob("*.y*ml")]


@click.group(name="workspace", help="Manage workflow workspaces.")
@click.group(name="workspace", help="Manage Workflow Workspaces.")
def workspace():
"""Manage Workspaces."""
"""Manage Workflow Workspaces."""
pass


Expand All @@ -45,7 +45,12 @@ def ls():
table.add_row(workspace.stem, workspace.as_posix())
table.add_row("", "From Local Configuration Folder", style="red italic")
for workspace in localspaces.glob("*.y*ml"):
table.add_row(workspace.stem, workspace.as_posix())
if workspace.stem == "workspace":
table.add_row(
f"{workspace.stem} (active)", workspace.as_posix(), style="italic"
)
else:
table.add_row(workspace.stem, workspace.as_posix())
console.print(table)


Expand Down

0 comments on commit 08ce5e3

Please sign in to comment.