Skip to content

Commit 8e33f5d

Browse files
authored
show remaining time in CLI as h-m-s instead of seconds #2454 (#1134)
## Checklist - [x] I have read the [contribution guidelines](https://github.com/ooni/probe-cli/blob/master/CONTRIBUTING.md) - [x] reference issue for this pull request: [ Show remaining time in a human-readable way #2454 ](ooni/probe#2454) - [ ] if you changed anything related to how experiments work and you need to reflect these changes in the ooni/spec repository, please link to the related ooni/spec pull request: <!-- add URL here --> - [ ] if you changed code inside an experiment, make sure you bump its version number <!-- Reminder: Location of the issue tracker: https://github.com/ooni/probe --> ## Description Formatted remaining time in CLI (run websites) as standard time.Duration format, for example shows (1h7m19.018s) left instead of seconds for durations>=60 sec. Propose rounding to time.Millisecond instead of "%.2f", for cleaner code; only "time" package used, no extra dependencies.
1 parent 8bf3ce9 commit 8e33f5d

File tree

1 file changed

+1
-1
lines changed
  • cmd/ooniprobe/internal/log/handlers/cli

1 file changed

+1
-1
lines changed

cmd/ooniprobe/internal/log/handlers/cli/cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (h *Handler) TypedLog(t string, e *log.Entry) error {
112112
eta := e.Fields.Get("eta").(float64)
113113
var etaMessage string
114114
if eta >= 0 {
115-
etaMessage = fmt.Sprintf("(%ss left)", bold.Sprintf("%.2f", eta))
115+
etaMessage = fmt.Sprintf("(%s left)", bold.Sprintf("%s", time.Duration(eta*float64(time.Second)).Round(time.Millisecond)))
116116
}
117117
s := fmt.Sprintf(" %s %-25s %s",
118118
bold.Sprintf("%.2f%%", perc),

0 commit comments

Comments
 (0)