1717package stop
1818
1919import (
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 : `
3942cordium 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
4754func 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