@@ -20,6 +20,7 @@ import (
2020 "context"
2121 "fmt"
2222 "os"
23+ "time"
2324
2425 "github.com/octelium/cordium/client/cordium/commands/create/workspace"
2526 "github.com/octelium/cordium/client/cordium/commands/terminal"
@@ -37,6 +38,7 @@ import (
3738
3839type args struct {
3940 workspace.CreateWorkspaceArgs
41+ DoRemove bool
4042}
4143
4244var cmdArgs args
@@ -51,12 +53,14 @@ func init() {
5153 Cmd .PersistentFlags ().StringVarP (& cmdArgs .Dockerfile , "dockerfile" , "" , "" ,
5254 `Provide a Dockerfile file path to build the Container image from it` )
5355 Cmd .PersistentFlags ().BoolVarP (& cmdArgs .Ephemeral , "ephemeral" , "" , false , "Set the Workspace storage to be ephemeral" )
56+ Cmd .PersistentFlags ().BoolVarP (& cmdArgs .DoRemove , "rm" , "" , false , "Automatically remove the Workspace after the run" )
5457}
5558
5659var Cmd = & cobra.Command {
5760 Use : "run" ,
5861 Short : "Run a Workspace" ,
5962 Example : `
63+ cordium run
6064cordium run abc
6165 ` ,
6266 RunE : func (cmd * cobra.Command , args []string ) error {
@@ -105,7 +109,22 @@ func doCmd(cmd *cobra.Command, args []string) error {
105109 }
106110 }
107111
108- return doRun (ctx , conn , ws )
112+ if err := doRun (ctx , conn , ws ); err != nil {
113+ zap .L ().Debug ("doRun exited with err" , zap .Error (err ))
114+ }
115+
116+ if cmdArgs .DoRemove {
117+ ctx , cancel := context .WithTimeout (context .Background (), 6 * time .Second )
118+ defer cancel ()
119+
120+ if _ , err := c .DeleteWorkspace (ctx , & metav1.DeleteOptions {
121+ Uid : ws .Metadata .Uid ,
122+ }); err != nil {
123+ return err
124+ }
125+ }
126+
127+ return nil
109128}
110129
111130func doRun (ctx context.Context , conn * grpc.ClientConn , ws * pb.Workspace ) error {
0 commit comments