mirror of
https://github.com/coder/coder.git
synced 2025-07-08 11:39:50 +00:00
This changes all "coder workspace *" commands to root. A few of these were already at the root, like SSH. The inconsistency made for a confusing experience.
43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
package cli
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/coder/coder/cli/cliui"
|
|
"github.com/coder/coder/coderd/database"
|
|
"github.com/coder/coder/codersdk"
|
|
)
|
|
|
|
// nolint
|
|
func delete() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "delete <workspace>",
|
|
Aliases: []string{"rm"},
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
client, err := createClient(cmd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
organization, err := currentOrganization(cmd, client)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), organization.ID, codersdk.Me, args[0])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
before := time.Now()
|
|
build, err := client.CreateWorkspaceBuild(cmd.Context(), workspace.ID, codersdk.CreateWorkspaceBuildRequest{
|
|
Transition: database.WorkspaceTransitionDelete,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return cliui.WorkspaceBuild(cmd.Context(), cmd.OutOrStdout(), client, build.ID, before)
|
|
},
|
|
}
|
|
}
|