feat(cli): start workspace in no-wait mode (#17087)

Fixes: https://github.com/coder/coder/issues/16408
This commit is contained in:
Marcin Tojek
2025-03-25 13:54:53 +01:00
committed by GitHub
parent cd19e79d9b
commit 56082f3b83
4 changed files with 60 additions and 1 deletions

View File

@ -17,6 +17,8 @@ func (r *RootCmd) start() *serpent.Command {
var (
parameterFlags workspaceParameterFlags
bflags buildFlags
noWait bool
)
client := new(codersdk.Client)
@ -28,7 +30,15 @@ func (r *RootCmd) start() *serpent.Command {
serpent.RequireNArgs(1),
r.InitClient(client),
),
Options: serpent.OptionSet{cliui.SkipPromptOption()},
Options: serpent.OptionSet{
{
Flag: "no-wait",
Description: "Return immediately after starting the workspace.",
Value: serpent.BoolOf(&noWait),
Hidden: false,
},
cliui.SkipPromptOption(),
},
Handler: func(inv *serpent.Invocation) error {
workspace, err := namedWorkspace(inv.Context(), client, inv.Args[0])
if err != nil {
@ -80,6 +90,11 @@ func (r *RootCmd) start() *serpent.Command {
}
}
if noWait {
_, _ = fmt.Fprintf(inv.Stdout, "The %s workspace has been started in no-wait mode. Workspace is building in the background.\n", cliui.Keyword(workspace.Name))
return nil
}
err = cliui.WorkspaceBuild(inv.Context(), inv.Stdout, client, build.ID)
if err != nil {
return err