From 0ba7db1a70b11aaec63e3eae9050e31ac6f225fe Mon Sep 17 00:00:00 2001 From: Nikolay Edigaryev Date: Tue, 4 Jul 2023 18:11:26 +0400 Subject: [PATCH] orchard list vms: add "Created" row (#106) --- go.mod | 2 +- go.sum | 3 ++- internal/command/list/vms.go | 7 +++++-- internal/command/list/workers.go | 5 ++++- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 8030591..5a93db3 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/avast/retry-go/v4 v4.3.3 github.com/deckarep/golang-set/v2 v2.1.0 github.com/dgraph-io/badger/v3 v3.2103.5 - github.com/dustin/go-humanize v1.0.0 + github.com/dustin/go-humanize v1.0.1 github.com/gin-gonic/gin v1.9.0 github.com/go-openapi/runtime v0.25.0 github.com/gofrs/flock v0.8.1 diff --git a/go.sum b/go.sum index 26a759a..1de4339 100644 --- a/go.sum +++ b/go.sum @@ -97,8 +97,9 @@ github.com/dgraph-io/ristretto v0.1.1 h1:6CWw5tJNgpegArSHpNHJKldNeq03FQCwYvfMVWa github.com/dgraph-io/ristretto v0.1.1/go.mod h1:S1GPSBCYCIhmVNfcth17y2zZtQT6wzkzgwUve0VDWWA= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= -github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= +github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= +github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= diff --git a/internal/command/list/vms.go b/internal/command/list/vms.go index 5fc0576..ac8ac19 100644 --- a/internal/command/list/vms.go +++ b/internal/command/list/vms.go @@ -3,8 +3,10 @@ package list import ( "fmt" "github.com/cirruslabs/orchard/pkg/client" + "github.com/dustin/go-humanize" "github.com/gosuri/uitable" "github.com/spf13/cobra" + "time" ) func newListVMsCommand() *cobra.Command { @@ -38,12 +40,13 @@ func runListVMs(cmd *cobra.Command, args []string) error { table := uitable.New() - table.AddRow("Name", "Image", "Status", "Restart policy") + table.AddRow("Name", "Created", "Image", "Status", "Restart policy") for _, vm := range vms { restartPolicyInfo := fmt.Sprintf("%s (%d restarts)", vm.RestartPolicy, vm.RestartCount) + createdAtInfo := humanize.RelTime(vm.CreatedAt, time.Now(), "ago", "in the future") - table.AddRow(vm.Name, vm.Image, vm.Status, restartPolicyInfo) + table.AddRow(vm.Name, createdAtInfo, vm.Image, vm.Status, restartPolicyInfo) } fmt.Println(table) diff --git a/internal/command/list/workers.go b/internal/command/list/workers.go index d1fe37e..b7cae3c 100644 --- a/internal/command/list/workers.go +++ b/internal/command/list/workers.go @@ -6,6 +6,7 @@ import ( "github.com/dustin/go-humanize" "github.com/gosuri/uitable" "github.com/spf13/cobra" + "time" ) func newListWorkersCommand() *cobra.Command { @@ -42,7 +43,9 @@ func runListWorkers(cmd *cobra.Command, args []string) error { table.AddRow("Name", "Last seen", "Scheduling paused") for _, worker := range workers { - table.AddRow(worker.Name, humanize.Time(worker.LastSeen), worker.SchedulingPaused) + lastSeenInfo := humanize.RelTime(worker.LastSeen, time.Now(), "ago", "in the future") + + table.AddRow(worker.Name, lastSeenInfo, worker.SchedulingPaused) } fmt.Println(table)