diff --git a/images/images.go b/images/images.go index 98211eb..5160859 100644 --- a/images/images.go +++ b/images/images.go @@ -113,7 +113,7 @@ func download(r *dbImage) error { bar := progressbar.DefaultBytes( resp.ContentLength, - fmt.Sprintf("Downloading: %s ", r.URL), + "Downloading", ) if _, err = io.Copy(io.MultiWriter(tmpFile, bar), resp.Body); err != nil { return err diff --git a/progress/progress.go b/progress/progress.go index d8eafd9..bd76913 100644 --- a/progress/progress.go +++ b/progress/progress.go @@ -8,12 +8,20 @@ import ( type StopFunc func() -func Show(title string) StopFunc { +func Immediate(msg ...string) { + var msgs string + for _, m := range msg { + msgs += m + " " + } + fmt.Printf("\r✔ %s\n", msgs) +} + +func Show(msg string) StopFunc { quit := make(chan bool, 1) - i, appendln := 0, false + i, isWritten := 0, false bar := progressbar.NewOptions(-1, - progressbar.OptionSetDescription(title), + progressbar.OptionSetDescription(msg), progressbar.OptionSpinnerType(11), ) @@ -27,7 +35,7 @@ func Show(title string) StopFunc { if i == 0 { time.Sleep(1 * time.Second) } else { - appendln = true + isWritten = true _ = bar.Add(1) time.Sleep(100 * time.Millisecond) } @@ -38,9 +46,8 @@ func Show(title string) StopFunc { return func() { quit <- true - if appendln { - fmt.Printf("\r✔ %s", title) - fmt.Println() + if isWritten { + fmt.Printf("\r✔ %s\n", msg) } } } diff --git a/vms/create.go b/vms/create.go index 64c36d4..7a22387 100644 --- a/vms/create.go +++ b/vms/create.go @@ -8,6 +8,7 @@ import ( "github.com/mhewedy/vermin/command/ssh" "github.com/mhewedy/vermin/db" "github.com/mhewedy/vermin/images" + "github.com/mhewedy/vermin/progress" "os" "path/filepath" "runtime" @@ -65,7 +66,7 @@ func Create(imageName string, script string, cpus int, mem int) (string, error) } func setNetworkAdapter(vmName string) error { - fmt.Println("Setting bridged network adapter") + progress.Immediate("Setting bridged network adapter") r, err := command.VBoxManage("list", "bridgedifs").Call() if err != nil { return err @@ -110,7 +111,7 @@ func provision(vmName string, script string) error { } func start(vmName string) error { - fmt.Println("Starting", vmName) + progress.Immediate("Starting", vmName) if _, err := command.VBoxManage("startvm", vmName, "--type", "headless").Call(); err != nil { return err }