Skip to content

Commit

Permalink
refactor: newcluster and workspace command
Browse files Browse the repository at this point in the history
  • Loading branch information
dtdang committed Nov 1, 2024
1 parent a83e107 commit 36d9a01
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions silverback/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
)
from silverback.cluster.client import ClusterClient, PlatformClient
from silverback.cluster.types import ClusterTier, LogLevel, ResourceStatus
from silverback.exceptions import ClientError
from silverback.runner import PollingRunner, WebsocketRunner
from silverback.worker import run_worker

Expand Down Expand Up @@ -220,39 +221,37 @@ def workspace_info(platform: PlatformClient, workspace: str):
"-n",
"--name",
"workspace_name",
required=True,
help="Name for new workspace",
)
@click.option(
"-s",
"--slug",
"workspace_slug",
required=True,
help="Slug for new workspace",
)
@platform_client
def new_workspace(
platform: PlatformClient,
workspace_name: str,
workspace_slug: str,
workspace_name: str | None,
workspace_slug: str | None,
):
"""Create a new workspace"""

if workspace_name:
click.echo(f"name: {workspace_name}")
click.echo(f"slug: {workspace_slug or workspace_name.lower().replace(' ', '-')}")

elif workspace_slug:
click.echo(f"slug: {workspace_slug}")
workspace_name = workspace_name or workspace_slug
workspace_slug = workspace_slug or (
workspace_name.lower().replace(" ", "-") if workspace_name else None
)

else:
raise click.UsageError("Must provide a name or a slug/name combo")
if not workspace_name:
raise ClientError("Must provide a name or a slug/name combo")

platform.create_workspace(
workspace_name=workspace_name,
workspace_slug=workspace_slug,
)
click.echo(f"{click.style('SUCCESS', fg='green')}: Created '{workspace_name}'")
click.echo(f"name: {workspace_name}")
click.echo(f"slug: {workspace_slug}")


@workspaces.command(name="update", section="Platform Commands (https://silverback.apeworx.io)")
Expand Down Expand Up @@ -356,21 +355,21 @@ def new_cluster(
if not (workspace_client := platform.workspaces.get(workspace)):
raise click.BadOptionUsage("workspace", f"Unknown workspace '{workspace}'")

if cluster_name:
click.echo(f"name: {cluster_name}")
click.echo(f"slug: {cluster_slug or cluster_name.lower().replace(' ', '-')}")

elif cluster_slug:
click.echo(f"slug: {cluster_slug}")
cluster_name = cluster_name or cluster_slug
cluster_slug = cluster_slug or (
cluster_name.lower().replace(" ", "-") if cluster_name else None
)

else:
raise click.UsageError("Must provide a name or a slug/name combo")
if not cluster_name:
raise ClientError("Must provide a name or a slug/name combo")

cluster = workspace_client.create_cluster(
cluster_name=cluster_name,
cluster_slug=cluster_slug,
)
click.echo(f"{click.style('SUCCESS', fg='green')}: Created '{cluster.name}'")
click.echo(f"name: {cluster_name}")
click.echo(f"slug: {cluster_slug}")

if cluster.status == ResourceStatus.CREATED:
click.echo(
Expand Down

0 comments on commit 36d9a01

Please sign in to comment.