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
|
// mostly just functions related to making STDOUT
|
||||||
// more readable by us humans
|
// 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
|
// 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
|
// are in text columns and rows that can be easily read in a terminal
|
||||||
|
|
||||||
|
@ -14,6 +14,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -146,34 +148,26 @@ func (d *Droplet) SprintDumpHeader() string {
|
||||||
macs = append(macs, n.Mac)
|
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)
|
header := fmt.Sprintf("%-4.4s%20s %-8s", d.Current.State, strings.Join(macs, " "), d.Current.Hypervisor)
|
||||||
|
|
||||||
if d.Current == nil {
|
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 {
|
switch d.Current.State {
|
||||||
case DropletState_ON:
|
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)
|
header += fmt.Sprintf(" (on :%3s)", dur)
|
||||||
case DropletState_OFF:
|
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)
|
header += fmt.Sprintf(" (off:%3s)", dur)
|
||||||
default:
|
default:
|
||||||
header += fmt.Sprintf(" (?? :%3s)", "")
|
header += fmt.Sprintf(" (?? :%3s)", dur)
|
||||||
}
|
}
|
||||||
return header
|
return header
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue