Skip to content

Commit bb374c8

Browse files
committed
client/cordium - stop the Workspace from within the Workspace
1 parent dc4737e commit bb374c8

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

  • client/cordium/commands/stop

client/cordium/commands/stop/cmd.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
package stop
1818

1919
import (
20+
"os"
21+
2022
pb "github.com/octelium/octelium/apis/main/cordiumv1"
2123
"github.com/octelium/octelium/apis/main/metav1"
2224
"github.com/octelium/octelium/client/common/client"
2325
"github.com/octelium/octelium/client/common/cliutils"
26+
"github.com/pkg/errors"
2427
"github.com/spf13/cobra"
2528
)
2629

@@ -37,11 +40,15 @@ var Cmd = &cobra.Command{
3740
Short: "Stop a Workspace",
3841
Example: `
3942
cordium stop abc
43+
# Stop the Workspace from within the Workspace
44+
cordium stop
45+
# With an environment variable
46+
CORDIUM_NAME=abc cordium stop
4047
`,
4148
RunE: func(cmd *cobra.Command, args []string) error {
4249
return doCmd(cmd, args)
4350
},
44-
Args: cobra.ExactArgs(1),
51+
Args: cobra.MaximumNArgs(1),
4552
}
4653

4754
func doCmd(cmd *cobra.Command, args []string) error {
@@ -60,15 +67,23 @@ func doCmd(cmd *cobra.Command, args []string) error {
6067

6168
c := pb.NewMainServiceClient(conn)
6269

70+
name := i.FirstArg()
71+
if name == "" {
72+
name = os.Getenv("CORDIUM_NAME")
73+
}
74+
if name == "" {
75+
return errors.Errorf("You need to provide the Workspace name")
76+
}
77+
6378
if _, err := c.StopWorkspace(ctx, &pb.StopWorkspaceRequest{
6479
WorkspaceRef: &metav1.ObjectReference{
65-
Name: i.FirstArg(),
80+
Name: name,
6681
},
6782
}); err != nil {
6883
return err
6984
}
7085

71-
cliutils.LineNotify("Successfully stopped the Workspace: %s\n", i.FirstArg())
86+
cliutils.LineNotify("Successfully stopped the Workspace: %s\n", name)
7287

7388
return nil
7489
}

0 commit comments

Comments
 (0)