瀏覽代碼

Improve the progress bar ending

Vadim Markovtsev 7 年之前
父節點
當前提交
8ea2b102dc
共有 1 個文件被更改,包括 4 次插入2 次删除
  1. 4 2
      cmd/hercules/main.go

+ 4 - 2
cmd/hercules/main.go

@@ -38,6 +38,7 @@ import (
 	"os"
 	"plugin"
 	"runtime/pprof"
+	"strconv"
 	"strings"
 
 	"gopkg.in/src-d/go-billy.v3/osfs"
@@ -179,9 +180,11 @@ func main() {
 	pipeline := hercules.NewPipeline(repository)
 	pipeline.SetFeaturesFromFlags()
 	progress := mpb.New(mpb.Output(os.Stderr))
+	defer progress.Stop()
 	var bar *mpb.Bar
 	pipeline.OnProgress = func(commit, length int) {
 		if bar == nil {
+			width := len(strconv.Itoa(length)) * 2 + 3
 			bar = progress.AddBar(int64(length + 1),
 				mpb.PrependDecorators(decor.DynamicName(
 					func (stats *decor.Statistics) string {
@@ -189,7 +192,7 @@ func main() {
 							return fmt.Sprintf("%d / %d", stats.Current, length)
 						}
 						return "finalizing"
-					}, 10, 0)),
+					}, width, 0)),
 				mpb.AppendDecorators(decor.ETA(4, 0)),
 			)
 		}
@@ -220,7 +223,6 @@ func main() {
 	if err != nil {
 		panic(err)
 	}
-	progress.Stop()
 	fmt.Fprint(os.Stderr, "writing...\r")
 	begin := commits[0].Author.When.Unix()
 	end := commits[len(commits)-1].Author.When.Unix()