Skip to content

Commit

Permalink
feat(cli/main.py): adding logging on top level function (#37)
Browse files Browse the repository at this point in the history
Logging info about actual workspace being used.
  • Loading branch information
odarotto authored May 27, 2024
1 parent 4dfb30a commit 7820c62
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions workflow/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
"""Workflow command line interface."""

import click
from rich.console import Console

# from workflow.cli.buckets import buckets
from workflow.cli.pipelines import pipelines
from workflow.cli.results import results
from workflow.cli.run import run
from workflow.cli.schedules import schedules
from workflow.cli.workspace import workspace
from workflow.utils.read import get_active_workspace

console = Console()


@click.group()
def cli():
"""Workflow Command Line Interface."""
# ? Get workspace
message = get_active_workspace()
console.print(message)
pass


Expand Down
29 changes: 29 additions & 0 deletions workflow/utils/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

from requests import get
from requests.exceptions import RequestException
from rich.text import Text
from yaml import safe_load

from workflow.cli.workspace import localspaces, localstems, modulespaces, modulestems
from workflow.utils.logger import get_logger

logger = get_logger("workflow.utils.read")
Expand Down Expand Up @@ -83,6 +85,33 @@ def filename(source: str) -> Any:
raise error


def get_active_workspace() -> Text:
"""Returns a Text with info about the active workspace.
Returns
-------
Text
Text instance with info.
"""
_workspace = "active"
text = Text()
if _workspace in localstems:
for possibility in localspaces.glob(f"{_workspace}.y*ml"):
config = workspace(possibility)
text.append("Currently using ", style="green")
text.append(f"{config['workspace']} ", style="blue")
text.append("workspace.", style="green")
elif _workspace in modulestems:
for possibility in modulespaces.glob(f"{_workspace}.y*ml"):
config = workspace(possibility)
text.append("Currently using ", style="green")
text.append(f"{config['workspace']} ", style="blue")
text.append("workspace.", style="green")
else:
text.append("There is not active workspace", style="red")
return text


def is_valid_url(url: str) -> bool:
"""Return True if the URL is valid.
Expand Down

0 comments on commit 7820c62

Please sign in to comment.