summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-01 02:01:11 -0500
committerJeff Carr <[email protected]>2024-11-01 02:01:11 -0500
commit20e958559e0a563f8b7c7b4bf4c4a95e328b1f37 (patch)
tree42d993d9fcacf030ce48010c83a03f927adaedcd
parentadb44a864f37e99e775460cf74ec6701fc34ebf8 (diff)
fixes for libvirt domain import
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--helpers.go4
-rw-r--r--human.go48
2 files changed, 38 insertions, 14 deletions
diff --git a/helpers.go b/helpers.go
index 82e7c5c..5c1ec7f 100644
--- a/helpers.go
+++ b/helpers.go
@@ -42,6 +42,10 @@ func (d *Droplets) FormatTEXT() string {
return prototext.Format(d)
}
+func (d *Droplet) FormatTEXT() string {
+ return prototext.Format(d)
+}
+
func (e *Events) FormatTEXT() string {
return prototext.Format(e)
}
diff --git a/human.go b/human.go
index 02dc588..0ace136 100644
--- a/human.go
+++ b/human.go
@@ -115,15 +115,25 @@ func (d *Droplet) SprintHeader() string {
switch d.Current.State {
case DropletState_ON:
- dur := time.Since(d.Current.OnSince.AsTime()) // time since 'ON'
- header += fmt.Sprintf(" (on :%3s)", FormatDuration(dur))
+ var dur string
+ if d.Current.OnSince != nil {
+ dur = ""
+ } else {
+ t := time.Since(d.Current.OnSince.AsTime()) // time since 'OFF'
+ dur = FormatDuration(t)
+ }
+ header += fmt.Sprintf(" (on :%3s)", dur)
case DropletState_OFF:
- // everything is as it should be with this vm
- dur := time.Since(d.Current.OffSince.AsTime()) // time since 'OFF'
- header += fmt.Sprintf(" (off:%3s)", FormatDuration(dur))
+ 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:
- dur := time.Since(d.Current.OffSince.AsTime()) // use 'OFF' here?
- header += fmt.Sprintf(" (?? :%3s)", FormatDuration(dur))
+ header += fmt.Sprintf(" (?? :%3s)", "")
}
return header
}
@@ -143,15 +153,25 @@ func (d *Droplet) SprintDumpHeader() string {
switch d.Current.State {
case DropletState_ON:
- dur := time.Since(d.Current.OnSince.AsTime()) // time since 'ON'
- header += fmt.Sprintf(" (on :%3s)", FormatDuration(dur))
+ 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:
- // everything is as it should be with this vm
- dur := time.Since(d.Current.OffSince.AsTime()) // time since 'OFF'
- header += fmt.Sprintf(" (off:%3s)", FormatDuration(dur))
+ 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:
- dur := time.Since(d.Current.OffSince.AsTime()) // use 'OFF' here?
- header += fmt.Sprintf(" (?? :%3s)", FormatDuration(dur))
+ header += fmt.Sprintf(" (?? :%3s)", "")
}
return header
}