From 35d3c7b1a9aacc5858b607e0cfd1df37718197ca Mon Sep 17 00:00:00 2001 From: Muhammad Hewedy Date: Sat, 29 Aug 2020 00:18:54 +0300 Subject: [PATCH] execute gui command without checking if VM running or not --- cmd/gui.go | 5 +++-- vms/vms.go | 15 ++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/cmd/gui.go b/cmd/gui.go index fd3d603..14ffb3d 100644 --- a/cmd/gui.go +++ b/cmd/gui.go @@ -34,7 +34,8 @@ $ vermin gui vm_02 `, Run: func(cmd *cobra.Command, args []string) { vmName := args[0] - if err := vms.GUI(vmName); err != nil { + nocheck, _ := cmd.Flags().GetBool("nocheck") + if err := vms.GUI(vmName, nocheck); err != nil { fmt.Println(err) os.Exit(1) } @@ -59,5 +60,5 @@ func init() { // Cobra supports local flags which will only run when this command // is called directly, e.g.: - //guiCmd.Flags().BoolP("purge", "p", false, "Purge the IP cache") + guiCmd.Flags().BoolP("nocheck", "n", false, "open GUI without checking if the VM is running or not") } diff --git a/vms/vms.go b/vms/vms.go index 3ef1143..8fd4969 100644 --- a/vms/vms.go +++ b/vms/vms.go @@ -167,15 +167,16 @@ func Modify(vmName string, cpus int, mem int) error { return err } -func GUI(vmName string) error { - if err := checkRunningVM(vmName); err != nil { - return err - } +func GUI(vmName string, nocheck bool) error { + if !nocheck { + if err := checkRunningVM(vmName); err != nil { + return err + } - if err := ssh.EstablishConn(vmName); err != nil { - return err + if err := ssh.EstablishConn(vmName); err != nil { + return err + } } - return command.VBoxManage("startvm", "--type", "separate", vmName).Run() }