nettests: don't say ETA is infinite

1. only print time left if ETA is positive

2. skip ETA calculation with a single input

3. don't compute ETA for first entry[*]

[*] this is actually what avoids emitting infinite but the other
parts of this diff felt useful yak shaving as well.

Closes #91
This commit is contained in:
Simone Basso
2019-12-28 18:26:32 +01:00
parent 991b875bd9
commit 955509e6f8
2 changed files with 10 additions and 5 deletions
+6 -3
View File
@@ -110,10 +110,13 @@ func (h *Handler) TypedLog(t string, e *log.Entry) error {
case "progress":
perc := e.Fields.Get("percentage").(float64) * 100
eta := e.Fields.Get("eta").(float64)
s := fmt.Sprintf(" %s %-25s (%ss left)",
var etaMessage string
if eta >= 0 {
etaMessage = fmt.Sprintf("(%ss left)", bold.Sprintf("%.2f", eta))
}
s := fmt.Sprintf(" %s %-25s %s",
bold.Sprintf("%.2f%%", perc),
e.Message,
bold.Sprintf("%.2f", eta))
e.Message, etaMessage)
fmt.Fprint(h.Writer, s)
fmt.Fprintln(h.Writer)
return nil