Skip to content

Commit

Permalink
execute gui command without checking if VM running or not
Browse files Browse the repository at this point in the history
  • Loading branch information
mhewedy committed Aug 28, 2020
1 parent 8e1c9b8 commit 35d3c7b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
5 changes: 3 additions & 2 deletions cmd/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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")
}
15 changes: 8 additions & 7 deletions vms/vms.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down

0 comments on commit 35d3c7b

Please sign in to comment.