Skip to content

Commit 08ce5e3

Browse files
committed
fix(cli): improved cli structure
1 parent 4d90dbe commit 08ce5e3

File tree

8 files changed

+55
-40
lines changed

8 files changed

+55
-40
lines changed

workflow/cli/buckets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
)
2222

2323

24-
@click.group(name="buckets", help="Manage workflow buckets.")
24+
@click.group(name="buckets", help="Manage Workflow Buckets.")
2525
def buckets():
2626
"""Manage workflow pipelines."""
2727
pass

workflow/cli/configs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
@click.group(name="configs", help="Manage Workflow Configs. Version 2.")
3636
def configs():
37-
"""Manage workflow configs."""
37+
"""Manage Workflow Configs."""
3838
pass
3939

4040

workflow/cli/main.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Workflow command line interface."""
22

3+
from typing import List
4+
35
import click
46
from rich.console import Console
57

@@ -15,10 +17,18 @@
1517
console = Console()
1618

1719

18-
@click.group()
20+
class OrderedCommands(click.Group):
21+
"""Order Click Commands."""
22+
23+
def list_commands(self, ctx: click.Context) -> List[str]:
24+
"""List Commands."""
25+
return list(self.commands)
26+
27+
28+
@click.group(cls=OrderedCommands)
1929
def cli():
2030
"""Workflow Command Line Interface."""
21-
# ? Get workspace
31+
# ? Get Workspace
2232
message = get_active_workspace()
2333
console.print(message)
2434
pass

workflow/cli/pipelines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
@click.group(name="pipelines", help="Manage Workflow Pipelines.")
3333
def pipelines():
34-
"""Manage workflow pipelines."""
34+
"""Manage Workflow Pipelines."""
3535
pass
3636

3737

workflow/cli/results.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
yes_no_colors = {"yes": "green", "no": "red"}
3030

3131

32-
@click.group(name="results", help="Manage workflow results.")
32+
@click.group(name="results", help="Manage Workflow Results.")
3333
def results():
34-
"""Manage workflow results."""
34+
"""Manage Workflow Results."""
3535
pass
3636

3737

workflow/cli/run.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,8 @@
1919
logger = get_logger("workflow.cli")
2020

2121

22-
@click.command("run", short_help="Perform work.")
23-
@click.argument("bucket", type=str, required=True)
24-
@click.option(
25-
"-f",
26-
"--function",
27-
type=str,
28-
required=False,
29-
default=None,
30-
show_default=True,
31-
help="Override work function to execute. e.g `workflow.tasks.example`.",
32-
)
33-
@click.option(
34-
"-c",
35-
"--command",
36-
type=str,
37-
required=False,
38-
default=None,
39-
show_default=True,
40-
help="Override work command to execute. e.g `echo hello world`.",
41-
)
22+
@click.command("run", short_help="Fetch & Perform Work.")
23+
@click.argument("buckets", type=str, required=True)
4224
@click.option(
4325
"-s",
4426
"--site",
@@ -55,7 +37,7 @@
5537
required=False,
5638
default=None,
5739
show_default=True,
58-
help="filter work by tag, multiple values allowed.",
40+
help="filter work by tag.",
5941
)
6042
@click.option(
6143
"-p",
@@ -66,27 +48,46 @@
6648
show_default=True,
6749
help="filter work by parent.",
6850
)
51+
@click.option(
52+
"-f",
53+
"--function",
54+
type=str,
55+
required=False,
56+
default=None,
57+
show_default=True,
58+
help="overload function to execute.",
59+
)
60+
@click.option(
61+
"-c",
62+
"--command",
63+
type=str,
64+
required=False,
65+
default=None,
66+
show_default=True,
67+
help="overload command to execute.",
68+
)
6969
@click.option(
7070
"--lives",
71+
"-l",
7172
type=int,
72-
default=1,
73+
default=-1,
7374
show_default=True,
74-
help="number of times to attempt work.",
75+
help="count of work to perform.",
7576
)
7677
@click.option(
7778
"--sleep",
7879
type=int,
7980
default=30,
8081
show_default=True,
81-
help="sleep time between attempts.",
82+
help="sleep between work attempts.",
8283
)
8384
@click.option(
8485
"-w",
8586
"--workspace",
8687
type=click.Path(exists=True, file_okay=True, dir_okay=False, readable=True),
8788
default=DEFAULT_WORKSPACE_PATH,
8889
show_default=True,
89-
help="workspace config path.",
90+
help="workspace config.",
9091
)
9192
@click.option(
9293
"--log-level",
@@ -97,23 +98,22 @@
9798
)
9899
def run(
99100
bucket: str,
100-
function: str,
101-
command: str,
102101
site: str,
103102
tag: Tuple[str],
104103
parent: Optional[str],
104+
function: str,
105+
command: str,
105106
lives: int,
106107
sleep: int,
107108
workspace: str,
108109
log_level: str,
109110
):
110-
"""Perform work retrieved from the workflow buckets."""
111+
"""Fetch & Perform Work."""
111112
# Set logging level
112113
logger.root.setLevel(log_level)
113114
logger.root.handlers[0].setLevel(log_level)
114115
config = reader.workspace(workspace)
115116
baseurls = config.get("http", {}).get("baseurls", {})
116-
117117
buckets_url = baseurls.get("buckets", None)
118118
loki_url = baseurls.get("loki", None)
119119
products_url = baseurls.get("products", None)

workflow/cli/schedules.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
@click.group(name="schedules", help="Manage Workflow Schedules.")
3434
def schedules():
35-
"""Manage workflow Schedules."""
35+
"""Manage Workflow Schedules."""
3636
pass
3737

3838

workflow/cli/workspace.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
modulestems = [space.stem for space in modulespaces.glob("*.y*ml")]
2525

2626

27-
@click.group(name="workspace", help="Manage workflow workspaces.")
27+
@click.group(name="workspace", help="Manage Workflow Workspaces.")
2828
def workspace():
29-
"""Manage Workspaces."""
29+
"""Manage Workflow Workspaces."""
3030
pass
3131

3232

@@ -45,7 +45,12 @@ def ls():
4545
table.add_row(workspace.stem, workspace.as_posix())
4646
table.add_row("", "From Local Configuration Folder", style="red italic")
4747
for workspace in localspaces.glob("*.y*ml"):
48-
table.add_row(workspace.stem, workspace.as_posix())
48+
if workspace.stem == "workspace":
49+
table.add_row(
50+
f"{workspace.stem} (active)", workspace.as_posix(), style="italic"
51+
)
52+
else:
53+
table.add_row(workspace.stem, workspace.as_posix())
4954
console.print(table)
5055

5156

0 commit comments

Comments
 (0)