def develop_command(
    bento_dir: str,
    cluster: str | None,
    attach: str | None,
    env: tuple[str] | None,
    secret: tuple[str] | None,
    _rest_client: RestApiClient = Provide[BentoMLContainer.rest_api_client],
):
    """Create or attach to a codespace.

    Create a new codespace:

        $ bentoml code

    Attach to an existing codespace:

        $ bentoml code --attach <codespace-name>
    """
    import questionary

    if attach and (env or secret):
        raise CLIException("Cannot specify both --attach and --env or --secret")

    console = Console(highlight=False)
    if attach:
        deployment = bentoml.deployment.get(attach)
    else:
        with console.status("Fetching codespaces..."):
            current_user = _rest_client.v1.get_current_user()
            if current_user is None:
                raise CLIException("current user is not found")
            deployments = [
                d
                for d in bentoml.deployment.list(cluster=cluster, dev=True)
                if d.is_dev
                and d.created_by == current_user.name
                and d.get_status(False).status
                in [
                    DeploymentStatus.Deploying.value,
                    DeploymentStatus.Running.value,
                    DeploymentStatus.ScaledToZero.value,
                    DeploymentStatus.Failed.value,
                ]
            ]

        chosen = questionary.select(
            message="Select a codespace to attach to or create a new one",
            choices=[{"name": d.name, "value": d} for d in deployments]
            + [{"name": "Create a new codespace", "value": "new"}],
        ).ask()

        if chosen == "new":
            deployment = create_deployment(
                bento=bento_dir,
                cluster=cluster,
                dev=True,
                wait=False,
                env=env,
                secret=secret,
            )
        elif chosen is None:
            return
        else:
            if env or secret:
                rich.print(
                    "[yellow]Warning:[/] --env and --secret are ignored when attaching to an existing codespace"
                )
            deployment = t.cast(Deployment, chosen)
    deployment.watch(bento_dir)
Create or attach to a codespace.

Create a new codespace:

$ bentoml code

Attach to an existing codespace:

$ bentoml code --attach <codespace-name>
src/bentoml_cli/deployment.py