Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cli): new cluster and workspaces #166

Merged
merged 5 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 20 additions & 21 deletions silverback/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,39 +220,38 @@ 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:
if not workspace_name:
raise click.UsageError("Must provide a name or a slug/name combo")

platform.create_workspace(
workspace = 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"{click.style('SUCCESS', fg='green')}: "
f"Created '{workspace.name}' (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:
if not cluster_name:
raise click.UsageError("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"{click.style('SUCCESS', fg='green')}: Created '{cluster.name}' (slug: '{cluster.slug}')"
)

if cluster.status == ResourceStatus.CREATED:
click.echo(
Expand Down
4 changes: 2 additions & 2 deletions silverback/cluster/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,8 @@ def workspaces(self) -> dict[str, Workspace]:

def create_workspace(
self,
workspace_slug: str = "",
workspace_name: str = "",
workspace_slug: str | None = None,
workspace_name: str | None = None,
) -> Workspace:
response = self.post(
"/workspaces",
Expand Down
Loading