Write finalizes the summary and writes it
(w io.Writer)
| 62 | |
| 63 | // Write finalizes the summary and writes it |
| 64 | func (s *pingSummary) Write(w io.Writer) { |
| 65 | if s.Successful > 0 { |
| 66 | s.Avg = ptr.Ref(time.Duration(s.latencySum / float64(s.Successful) * float64(time.Second))) |
| 67 | } |
| 68 | if s.Successful > 1 { |
| 69 | s.Variance = ptr.Ref(time.Duration((s.m2 / float64(s.Successful-1)) * float64(time.Second))) |
| 70 | } |
| 71 | out, err := cliui.DisplayTable([]*pingSummary{s}, "", nil) |
| 72 | if err != nil { |
| 73 | _, _ = fmt.Fprintf(w, "Failed to display ping summary: %v\n", err) |
| 74 | return |
| 75 | } |
| 76 | width := len(strings.Split(out, "\n")[0]) |
| 77 | _, _ = fmt.Println(strings.Repeat("-", width)) |
| 78 | _, _ = fmt.Fprint(w, out) |
| 79 | } |
| 80 | |
| 81 | func (r *RootCmd) ping() *serpent.Command { |
| 82 | var ( |