Skip to content

Commit

Permalink
make remove command work with progress
Browse files Browse the repository at this point in the history
  • Loading branch information
mhewedy committed May 8, 2020
1 parent 0819825 commit 7d18d02
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (c *cmd) call(showProgress bool, msg string) (string, error) {
}

if showProgress {
stop := progress.Show(msg)
stop := progress.Show(msg, false)
defer stop()
}

Expand Down
2 changes: 1 addition & 1 deletion command/ssh/establish.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (b *delay) sleep(seconds int) error {

// EstablishConn make sure connection to the vm is established or return an error if not
func EstablishConn(vmName string) error {
stop := progress.Show("Establishing connection")
stop := progress.Show("Establishing connection", true)
defer stop()

d := &delay{
Expand Down
6 changes: 3 additions & 3 deletions progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func Immediate(msg ...string) {
fmt.Printf(format, msgs)
}

func Show(msg string) StopFunc {
func Show(msg string, initialWait bool) StopFunc {
quit := make(chan bool, 1)
i, isWritten := 0, false

Expand All @@ -35,8 +35,8 @@ func Show(msg string) StopFunc {
close(quit)
return
default:
if i == 0 {
time.Sleep(500 * time.Millisecond)
if initialWait && i == 0 {
time.Sleep(600 * time.Millisecond)
} else {
isWritten = true
_ = bar.Add(1)
Expand Down
8 changes: 5 additions & 3 deletions vms/vms.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/mhewedy/vermin/command/ssh"
"github.com/mhewedy/vermin/db"
"github.com/mhewedy/vermin/ip"
"github.com/mhewedy/vermin/progress"
"os"
)

Expand All @@ -34,7 +35,7 @@ func Stop(vmName string) error {
return err
}

fmt.Println("Stopping", vmName)
progress.Immediate("Stopping", vmName)
if _, err := command.VBoxManage("controlvm", vmName, "poweroff").Call(); err != nil {
return err
}
Expand Down Expand Up @@ -66,8 +67,9 @@ func Remove(vmName string, force bool) error {
return err
}
_ = Stop(vmName)
fmt.Println("Removing", vmName)
if _, err := command.VBoxManage("unregistervm", vmName, "--delete").Call(); err != nil {

msg := fmt.Sprintf("Removing %s", vmName)
if _, err := command.VBoxManage("unregistervm", vmName, "--delete").CallWithProgress(msg); err != nil {
return err
}
return os.RemoveAll(db.GetVMPath(vmName))
Expand Down

0 comments on commit 7d18d02

Please sign in to comment.