diff options
| author | Jeff Carr <[email protected]> | 2024-11-13 15:29:37 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-13 15:29:37 -0600 |
| commit | 3b63a3af2468ee5b51b1d17d1460b30e1236c85d (patch) | |
| tree | 415821a304bd5d9aca3820de10998ffec26e08e7 | |
| parent | 907981a92da0537617a4c9fe39093f23004f461c (diff) | |
better formattingv0.2.6
Signed-off-by: Jeff Carr <[email protected]>
| -rw-r--r-- | human.go | 30 |
1 files changed, 12 insertions, 18 deletions
@@ -3,7 +3,7 @@ package virtbuf // mostly just functions related to making STDOUT // more readable by us humans -// also function shortcuts the do limited formatting (haha, who remembers COBOL?) +// also function shortcuts the do fixed limited formatting (it's like COBOL) // so reporting tables of the status of what droplets and hypervisors // are in text columns and rows that can be easily read in a terminal @@ -14,6 +14,8 @@ import ( "strings" "time" + "google.golang.org/protobuf/types/known/timestamppb" + "go.wit.com/log" ) @@ -146,34 +148,26 @@ func (d *Droplet) SprintDumpHeader() string { macs = append(macs, n.Mac) } - // this line in golang could replace 80 lines of COBOL header := fmt.Sprintf("%-4.4s%20s %-8s", d.Current.State, strings.Join(macs, " "), d.Current.Hypervisor) if d.Current == nil { - d.Current = new(Current) + return header } + if d.Current.OnSince == nil { + d.Current.OnSince = timestamppb.New(time.Now()) + } + + t := time.Since(d.Current.OnSince.AsTime()) // time since 'ON' + dur := FormatDuration(t) + switch d.Current.State { case DropletState_ON: - var dur string - if d.Current.OnSince != nil { - dur = "" - } else { - t := time.Since(d.Current.OnSince.AsTime()) // time since 'ON' - dur = FormatDuration(t) - } header += fmt.Sprintf(" (on :%3s)", dur) case DropletState_OFF: - var dur string - if d.Current.OffSince != nil { - dur = "" - } else { - t := time.Since(d.Current.OffSince.AsTime()) // time since 'OFF' - dur = FormatDuration(t) - } header += fmt.Sprintf(" (off:%3s)", dur) default: - header += fmt.Sprintf(" (?? :%3s)", "") + header += fmt.Sprintf(" (?? :%3s)", dur) } return header } |
