diff --git a/silverback/_cli.py b/silverback/_cli.py index 2538a062..5823d1b3 100644 --- a/silverback/_cli.py +++ b/silverback/_cli.py @@ -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)") @@ -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( diff --git a/silverback/cluster/client.py b/silverback/cluster/client.py index a3a6c563..708da4ea 100644 --- a/silverback/cluster/client.py +++ b/silverback/cluster/client.py @@ -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",