better formatting
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
907981a92d
commit
3b63a3af24
30
human.go
30
human.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue