From 73f596e37c6c12abc1e6fc0e39ffb23c05fa3d47 Mon Sep 17 00:00:00 2001 From: Paul Larsen Date: Sun, 25 Feb 2024 13:44:44 +0000 Subject: [PATCH 1/3] Fix pagination for region availability command + consolidate metadata nil pointer checks --- cmd/applications/printer.go | 3 ++- cmd/backups/printer.go | 2 +- cmd/baremetal/printer.go | 6 ++--- cmd/billing/printer.go | 6 ++--- cmd/blockstorage/printer.go | 2 +- cmd/containerregistry/printer.go | 6 ++--- cmd/dns/printer.go | 4 ++-- cmd/firewall/printer.go | 4 ++-- cmd/instance/printer.go | 4 ++-- cmd/ip/printer.go | 4 ++-- cmd/iso/printer.go | 4 ++-- cmd/kubernetes/printer.go | 6 ++--- cmd/loadbalancer/printer.go | 8 +++---- cmd/objectstorage/printer.go | 4 ++-- cmd/operatingsystems/printer.go | 2 +- cmd/plans/printer.go | 4 ++-- cmd/printer/printer.go | 41 ++++++++++++++++++++++---------- cmd/regions/printer.go | 5 ++-- cmd/reservedip/printer.go | 2 +- cmd/script/printer.go | 2 +- cmd/snapshot/printer.go | 2 +- cmd/sshkeys/printer.go | 2 +- cmd/users/printer.go | 2 +- cmd/vpc/printer.go | 3 ++- cmd/vpc2/printer.go | 4 ++-- 25 files changed, 76 insertions(+), 56 deletions(-) diff --git a/cmd/applications/printer.go b/cmd/applications/printer.go index b24d8613..1ee07def 100644 --- a/cmd/applications/printer.go +++ b/cmd/applications/printer.go @@ -4,6 +4,7 @@ import ( "strconv" "github.com/vultr/govultr/v3" + "github.com/vultr/vultr-cli/v3/cmd/printer" ) @@ -62,5 +63,5 @@ func (a *ApplicationsPrinter) Data() [][]string { // Paging validates and forms the paging data for output func (a *ApplicationsPrinter) Paging() [][]string { - return printer.NewPaging(a.Meta.Total, &a.Meta.Links.Next, &a.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(a.Meta).Compose() } diff --git a/cmd/backups/printer.go b/cmd/backups/printer.go index 3d123252..e5871a5b 100644 --- a/cmd/backups/printer.go +++ b/cmd/backups/printer.go @@ -51,7 +51,7 @@ func (b *BackupsPrinter) Data() [][]string { // Paging ... func (b *BackupsPrinter) Paging() [][]string { - return printer.NewPaging(b.Meta.Total, &b.Meta.Links.Next, &b.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(b.Meta).Compose() } // ====================================== diff --git a/cmd/baremetal/printer.go b/cmd/baremetal/printer.go index 1a67c367..6ffa4038 100644 --- a/cmd/baremetal/printer.go +++ b/cmd/baremetal/printer.go @@ -49,7 +49,7 @@ func (b *BareMetalsPrinter) Data() [][]string { data = append(data, []string{ b.BareMetals[i].ID, b.BareMetals[i].MainIP, - b.BareMetals[i].Tag, //nolint: staticcheck + b.BareMetals[i].Tag, // nolint: staticcheck strconv.Itoa(b.BareMetals[i].MacAddress), b.BareMetals[i].Label, b.BareMetals[i].Os, @@ -67,7 +67,7 @@ func (b *BareMetalsPrinter) Data() [][]string { // Paging ... func (b *BareMetalsPrinter) Paging() [][]string { - return printer.NewPaging(b.Meta.Total, &b.Meta.Links.Next, &b.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(b.Meta).Compose() } // ====================================== @@ -111,7 +111,7 @@ func (b *BareMetalPrinter) Data() [][]string { return [][]string{0: { b.BareMetal.ID, b.BareMetal.MainIP, - b.BareMetal.Tag, //nolint: staticcheck + b.BareMetal.Tag, // nolint: staticcheck strconv.Itoa(b.BareMetal.MacAddress), b.BareMetal.Label, b.BareMetal.Os, diff --git a/cmd/billing/printer.go b/cmd/billing/printer.go index fdb9a030..bb34374e 100644 --- a/cmd/billing/printer.go +++ b/cmd/billing/printer.go @@ -60,7 +60,7 @@ func (b *BillingHistoryPrinter) Data() [][]string { // Paging ... func (b *BillingHistoryPrinter) Paging() [][]string { - return printer.NewPaging(b.Meta.Total, &b.Meta.Links.Next, &b.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(b.Meta).Compose() } // ====================================== @@ -113,7 +113,7 @@ func (b *BillingInvoicesPrinter) Data() [][]string { // Paging ... func (b *BillingInvoicesPrinter) Paging() [][]string { - return printer.NewPaging(b.Meta.Total, &b.Meta.Links.Next, &b.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(b.Meta).Compose() } // ====================================== @@ -217,5 +217,5 @@ func (b *BillingInvoiceItemsPrinter) Data() [][]string { // Paging ... func (b *BillingInvoiceItemsPrinter) Paging() [][]string { - return printer.NewPaging(b.Meta.Total, &b.Meta.Links.Next, &b.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(b.Meta).Compose() } diff --git a/cmd/blockstorage/printer.go b/cmd/blockstorage/printer.go index 6ed35044..1ede8c00 100644 --- a/cmd/blockstorage/printer.go +++ b/cmd/blockstorage/printer.go @@ -67,7 +67,7 @@ func (b *BlockStoragesPrinter) Data() [][]string { // Paging ... func (b *BlockStoragesPrinter) Paging() [][]string { - return printer.NewPaging(b.Meta.Total, &b.Meta.Links.Next, &b.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(b.Meta).Compose() } // ====================================== diff --git a/cmd/containerregistry/printer.go b/cmd/containerregistry/printer.go index 098fc94e..c6d2d148 100644 --- a/cmd/containerregistry/printer.go +++ b/cmd/containerregistry/printer.go @@ -133,7 +133,7 @@ func (c *ContainerRegistriesPrinter) Data() [][]string { // Paging ... func (c *ContainerRegistriesPrinter) Paging() [][]string { - return printer.NewPaging(c.Meta.Total, &c.Meta.Links.Next, &c.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(c.Meta).Compose() } // ====================================== @@ -234,7 +234,7 @@ func (c *ContainerRegistryRegionsPrinter) Data() [][]string { // Paging ... func (c *ContainerRegistryRegionsPrinter) Paging() [][]string { - return printer.NewPaging(c.Meta.Total, &c.Meta.Links.Next, &c.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(c.Meta).Compose() } // ====================================== @@ -340,7 +340,7 @@ func (c *ContainerRegistryRepositoriesPrinter) Data() [][]string { // Paging ... func (c *ContainerRegistryRepositoriesPrinter) Paging() [][]string { - return printer.NewPaging(c.Meta.Total, &c.Meta.Links.Next, &c.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(c.Meta).Compose() } // ====================================== diff --git a/cmd/dns/printer.go b/cmd/dns/printer.go index 4dea4dfd..f3523895 100644 --- a/cmd/dns/printer.go +++ b/cmd/dns/printer.go @@ -58,7 +58,7 @@ func (d *DNSRecordsPrinter) Data() [][]string { // Paging ... func (d *DNSRecordsPrinter) Paging() [][]string { - return printer.NewPaging(d.Meta.Total, &d.Meta.Links.Next, &d.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(d.Meta).Compose() } // ====================================== @@ -154,7 +154,7 @@ func (d *DNSDomainsPrinter) Data() [][]string { // Paging ... func (d *DNSDomainsPrinter) Paging() [][]string { - return printer.NewPaging(d.Meta.Total, &d.Meta.Links.Next, &d.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(d.Meta).Compose() } // ====================================== diff --git a/cmd/firewall/printer.go b/cmd/firewall/printer.go index 9fc1a53b..2b98ce2e 100644 --- a/cmd/firewall/printer.go +++ b/cmd/firewall/printer.go @@ -61,7 +61,7 @@ func (f *FirewallGroupsPrinter) Data() [][]string { // Paging ... func (f *FirewallGroupsPrinter) Paging() [][]string { - return printer.NewPaging(f.Meta.Total, &f.Meta.Links.Next, &f.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(f.Meta).Compose() } // ====================================== @@ -169,7 +169,7 @@ func (f *FirewallRulesPrinter) Data() [][]string { // Paging ... func (f *FirewallRulesPrinter) Paging() [][]string { - return printer.NewPaging(f.Meta.Total, &f.Meta.Links.Next, &f.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(f.Meta).Compose() } // ====================================== diff --git a/cmd/instance/printer.go b/cmd/instance/printer.go index b232694d..8d3970d3 100644 --- a/cmd/instance/printer.go +++ b/cmd/instance/printer.go @@ -67,7 +67,7 @@ func (i *InstancesPrinter) Data() [][]string { // Paging ... func (i *InstancesPrinter) Paging() [][]string { - return printer.NewPaging(i.Meta.Total, &i.Meta.Links.Next, &i.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(i.Meta).Compose() } // ====================================== @@ -509,5 +509,5 @@ func (v *VPC2sPrinter) Data() [][]string { // Paging ... func (v *VPC2sPrinter) Paging() [][]string { - return printer.NewPaging(v.Meta.Total, &v.Meta.Links.Next, &v.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(v.Meta).Compose() } diff --git a/cmd/ip/printer.go b/cmd/ip/printer.go index f05a5272..b6d72c38 100644 --- a/cmd/ip/printer.go +++ b/cmd/ip/printer.go @@ -51,7 +51,7 @@ func (i *IPv4sPrinter) Data() [][]string { // Paging ... func (i *IPv4sPrinter) Paging() [][]string { - return printer.NewPaging(i.Meta.Total, &i.Meta.Links.Next, &i.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(i.Meta).Compose() } // ====================================== @@ -99,5 +99,5 @@ func (i *IPv6sPrinter) Data() [][]string { // Paging ... func (i *IPv6sPrinter) Paging() [][]string { - return printer.NewPaging(i.Meta.Total, &i.Meta.Links.Next, &i.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(i.Meta).Compose() } diff --git a/cmd/iso/printer.go b/cmd/iso/printer.go index ccb36b3a..e1d434d5 100644 --- a/cmd/iso/printer.go +++ b/cmd/iso/printer.go @@ -60,7 +60,7 @@ func (i *ISOsPrinter) Data() [][]string { // Paging ... func (i *ISOsPrinter) Paging() [][]string { - return printer.NewPaging(i.Meta.Total, &i.Meta.Links.Next, &i.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(i.Meta).Compose() } // ====================================== @@ -154,5 +154,5 @@ func (i *PublicISOsPrinter) Data() [][]string { // Paging ... func (i *PublicISOsPrinter) Paging() [][]string { - return printer.NewPaging(i.Meta.Total, &i.Meta.Links.Next, &i.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(i.Meta).Compose() } diff --git a/cmd/kubernetes/printer.go b/cmd/kubernetes/printer.go index e567e5bc..1278d8e1 100644 --- a/cmd/kubernetes/printer.go +++ b/cmd/kubernetes/printer.go @@ -67,7 +67,7 @@ func (c *ClustersSummaryPrinter) Data() [][]string { // Paging ... func (c *ClustersSummaryPrinter) Paging() [][]string { - return printer.NewPaging(c.Meta.Total, &c.Meta.Links.Next, &c.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(c.Meta).Compose() } // ====================================== @@ -160,7 +160,7 @@ func (c *ClustersPrinter) Data() [][]string { // Paging ... func (c *ClustersPrinter) Paging() [][]string { - return printer.NewPaging(c.Meta.Total, &c.Meta.Links.Next, &c.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(c.Meta).Compose() } // ====================================== @@ -319,7 +319,7 @@ func (n *NodePoolsPrinter) Data() [][]string { // Paging ... func (n *NodePoolsPrinter) Paging() [][]string { - return printer.NewPaging(n.Meta.Total, &n.Meta.Links.Next, &n.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(n.Meta).Compose() } // ====================================== diff --git a/cmd/loadbalancer/printer.go b/cmd/loadbalancer/printer.go index 73636361..679aaf82 100644 --- a/cmd/loadbalancer/printer.go +++ b/cmd/loadbalancer/printer.go @@ -122,7 +122,7 @@ func (l *LBsPrinter) Data() [][]string { // Paging ... func (l *LBsPrinter) Paging() [][]string { - return printer.NewPaging(l.Meta.Total, &l.Meta.Links.Next, &l.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(l.Meta).Compose() } // ====================================== @@ -295,7 +295,7 @@ func (l *LBsSummaryPrinter) Data() [][]string { // Paging ... func (l *LBsSummaryPrinter) Paging() [][]string { - return printer.NewPaging(l.Meta.Total, &l.Meta.Links.Next, &l.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(l.Meta).Compose() } // ====================================== @@ -349,7 +349,7 @@ func (l *LBRulesPrinter) Data() [][]string { // Paging ... func (l *LBRulesPrinter) Paging() [][]string { - return printer.NewPaging(l.Meta.Total, &l.Meta.Links.Next, &l.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(l.Meta).Compose() } // ====================================== @@ -445,7 +445,7 @@ func (f *FWRulesPrinter) Data() [][]string { // Paging ... func (f *FWRulesPrinter) Paging() [][]string { - return printer.NewPaging(f.Meta.Total, &f.Meta.Links.Next, &f.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(f.Meta).Compose() } // ====================================== diff --git a/cmd/objectstorage/printer.go b/cmd/objectstorage/printer.go index e1989167..864e1f7a 100644 --- a/cmd/objectstorage/printer.go +++ b/cmd/objectstorage/printer.go @@ -64,7 +64,7 @@ func (o *ObjectStoragesPrinter) Data() [][]string { // Paging ... func (o *ObjectStoragesPrinter) Paging() [][]string { - return printer.NewPaging(o.Meta.Total, &o.Meta.Links.Next, &o.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(o.Meta).Compose() } // ====================================== @@ -168,7 +168,7 @@ func (o *ObjectStorageClustersPrinter) Data() [][]string { // Paging ... func (o *ObjectStorageClustersPrinter) Paging() [][]string { - return printer.NewPaging(o.Meta.Total, &o.Meta.Links.Next, &o.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(o.Meta).Compose() } // ====================================== diff --git a/cmd/operatingsystems/printer.go b/cmd/operatingsystems/printer.go index 49dcd751..a3d3dc47 100644 --- a/cmd/operatingsystems/printer.go +++ b/cmd/operatingsystems/printer.go @@ -56,5 +56,5 @@ func (o *OSPrinter) Data() [][]string { // Paging validates and forms the paging data for output func (o *OSPrinter) Paging() [][]string { - return printer.NewPaging(o.Meta.Total, &o.Meta.Links.Next, &o.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(o.Meta).Compose() } diff --git a/cmd/plans/printer.go b/cmd/plans/printer.go index ae4c9acc..07279ea7 100644 --- a/cmd/plans/printer.go +++ b/cmd/plans/printer.go @@ -82,7 +82,7 @@ func (p *PlansPrinter) Data() [][]string { // Paging validates and forms the paging data for output func (p *PlansPrinter) Paging() [][]string { - return printer.NewPaging(p.Meta.Total, &p.Meta.Links.Next, &p.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(p.Meta).Compose() } // MetalPlansPrinter represents the bare metal plans data from the API @@ -157,5 +157,5 @@ func (m *MetalPlansPrinter) Data() [][]string { // Paging validates and forms the paging data for output func (m *MetalPlansPrinter) Paging() [][]string { - return printer.NewPaging(m.Meta.Total, &m.Meta.Links.Next, &m.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(m.Meta).Compose() } diff --git a/cmd/printer/printer.go b/cmd/printer/printer.go index d135d8f3..a3a4a7ae 100644 --- a/cmd/printer/printer.go +++ b/cmd/printer/printer.go @@ -63,7 +63,7 @@ func (o *Output) Display(r ResourceOutput, err error) { defer o.flush() if err != nil { - //todo move this so it can follow the flow of the other printers and support json/yaml + // todo move this so it can follow the flow of the other printers and support json/yaml Error(err) } @@ -113,21 +113,33 @@ type Paging struct { CursorPrev string } -// NewPaging validates and intializes the paging data -func NewPaging(total int, next, prev *string) *Paging { - p := new(Paging) +// NewPagingFromMeta validates and initializes the paging data, from a govultr.Meta struct. +func NewPagingFromMeta(m *govultr.Meta) *Paging { + if m == nil { + // If no metadata, then no paging to show. + return nil + } + if m.Links == nil { + return NewPaging(m.Total, "", "") + } + return NewPaging(m.Total, m.Links.Next, m.Links.Prev) +} + +// NewPaging validates and initializes the paging data. +func NewPaging(total int, next, prev string) *Paging { + p := &Paging{ + Total: 0, + CursorNext: emptyPlaceholder, + CursorPrev: emptyPlaceholder, + } p.Total = total - if next != nil { - p.CursorNext = *next - } else { - p.CursorNext = emptyPlaceholder + if next != "" { + p.CursorNext = next } - if prev != nil { - p.CursorPrev = *prev - } else { - p.CursorPrev = emptyPlaceholder + if prev != "" { + p.CursorPrev = prev } return p @@ -135,6 +147,11 @@ func NewPaging(total int, next, prev *string) *Paging { // Compose returns the paging data for output func (p *Paging) Compose() [][]string { + if p == nil { + // If no paging information, don't show anything. + return nil + } + var display [][]string display = append(display, []string{"======================================"}, diff --git a/cmd/regions/printer.go b/cmd/regions/printer.go index 34d2724c..304dd4d4 100644 --- a/cmd/regions/printer.go +++ b/cmd/regions/printer.go @@ -2,6 +2,7 @@ package regions import ( "github.com/vultr/govultr/v3" + "github.com/vultr/vultr-cli/v3/cmd/printer" ) @@ -57,7 +58,7 @@ func (r *RegionsPrinter) Data() [][]string { // Paging validates and forms the paging data for output func (r *RegionsPrinter) Paging() [][]string { - return printer.NewPaging(r.Meta.Total, &r.Meta.Links.Next, &r.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(r.Meta).Compose() } // ====================================== @@ -107,5 +108,5 @@ func (r *RegionsAvailabilityPrinter) Data() [][]string { // Paging validates and forms the paging data for output func (r *RegionsAvailabilityPrinter) Paging() [][]string { - return printer.NewPaging(r.Meta.Total, &r.Meta.Links.Next, &r.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(r.Meta).Compose() } diff --git a/cmd/reservedip/printer.go b/cmd/reservedip/printer.go index 00e5056c..bb877518 100644 --- a/cmd/reservedip/printer.go +++ b/cmd/reservedip/printer.go @@ -60,7 +60,7 @@ func (r *ReservedIPsPrinter) Data() [][]string { // Paging ... func (r *ReservedIPsPrinter) Paging() [][]string { - return printer.NewPaging(r.Meta.Total, &r.Meta.Links.Next, &r.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(r.Meta).Compose() } // ====================================== diff --git a/cmd/script/printer.go b/cmd/script/printer.go index db2d57e9..2a756ea6 100644 --- a/cmd/script/printer.go +++ b/cmd/script/printer.go @@ -54,7 +54,7 @@ func (s *ScriptsPrinter) Data() [][]string { // Paging ... func (s *ScriptsPrinter) Paging() [][]string { - return printer.NewPaging(s.Meta.Total, &s.Meta.Links.Next, &s.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(s.Meta).Compose() } // ====================================== diff --git a/cmd/snapshot/printer.go b/cmd/snapshot/printer.go index 36cba506..c9e7fd9a 100644 --- a/cmd/snapshot/printer.go +++ b/cmd/snapshot/printer.go @@ -62,7 +62,7 @@ func (s *SnapshotsPrinter) Data() [][]string { // Paging ... func (s *SnapshotsPrinter) Paging() [][]string { - return printer.NewPaging(s.Meta.Total, &s.Meta.Links.Next, &s.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(s.Meta).Compose() } // ====================================== diff --git a/cmd/sshkeys/printer.go b/cmd/sshkeys/printer.go index 3924d0bc..a475acf2 100644 --- a/cmd/sshkeys/printer.go +++ b/cmd/sshkeys/printer.go @@ -47,7 +47,7 @@ func (s *SSHKeysPrinter) Data() [][]string { // Paging ... func (s *SSHKeysPrinter) Paging() [][]string { - return printer.NewPaging(s.Meta.Total, &s.Meta.Links.Next, &s.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(s.Meta).Compose() } // SSHKeyPrinter ... diff --git a/cmd/users/printer.go b/cmd/users/printer.go index 02ef8866..415c873b 100644 --- a/cmd/users/printer.go +++ b/cmd/users/printer.go @@ -51,7 +51,7 @@ func (u *UsersPrinter) Data() [][]string { // Paging ... func (u *UsersPrinter) Paging() [][]string { - return printer.NewPaging(u.Meta.Total, &u.Meta.Links.Next, &u.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(u.Meta).Compose() } // ====================================== diff --git a/cmd/vpc/printer.go b/cmd/vpc/printer.go index 845596fa..91f8461b 100644 --- a/cmd/vpc/printer.go +++ b/cmd/vpc/printer.go @@ -4,6 +4,7 @@ import ( "strconv" "github.com/vultr/govultr/v3" + "github.com/vultr/vultr-cli/v3/cmd/printer" ) @@ -58,7 +59,7 @@ func (s *VPCsPrinter) Data() [][]string { // Paging ... func (s *VPCsPrinter) Paging() [][]string { - return printer.NewPaging(s.Meta.Total, &s.Meta.Links.Next, &s.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(s.Meta).Compose() } // ====================================== diff --git a/cmd/vpc2/printer.go b/cmd/vpc2/printer.go index dc34f8f6..3d0aaf54 100644 --- a/cmd/vpc2/printer.go +++ b/cmd/vpc2/printer.go @@ -58,7 +58,7 @@ func (s *VPC2sPrinter) Data() [][]string { // Paging ... func (s *VPC2sPrinter) Paging() [][]string { - return printer.NewPaging(s.Meta.Total, &s.Meta.Links.Next, &s.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(s.Meta).Compose() } // ====================================== @@ -160,5 +160,5 @@ func (s *VPC2NodesPrinter) Data() [][]string { // Paging ... func (s *VPC2NodesPrinter) Paging() [][]string { - return printer.NewPaging(s.Meta.Total, &s.Meta.Links.Next, &s.Meta.Links.Prev).Compose() + return printer.NewPagingFromMeta(s.Meta).Compose() } From e2f1122bff6b46c8ea1a9c3c936c91cefc8df46f Mon Sep 17 00:00:00 2001 From: Paul Larsen Date: Mon, 26 Feb 2024 23:57:53 +0000 Subject: [PATCH 2/3] fix lint --- cmd/baremetal/printer.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/baremetal/printer.go b/cmd/baremetal/printer.go index 6ffa4038..208353ef 100644 --- a/cmd/baremetal/printer.go +++ b/cmd/baremetal/printer.go @@ -4,6 +4,7 @@ import ( "strconv" "github.com/vultr/govultr/v3" + "github.com/vultr/vultr-cli/v3/cmd/printer" ) @@ -49,7 +50,7 @@ func (b *BareMetalsPrinter) Data() [][]string { data = append(data, []string{ b.BareMetals[i].ID, b.BareMetals[i].MainIP, - b.BareMetals[i].Tag, // nolint: staticcheck + b.BareMetals[i].Tag, //nolint: staticcheck strconv.Itoa(b.BareMetals[i].MacAddress), b.BareMetals[i].Label, b.BareMetals[i].Os, @@ -111,7 +112,7 @@ func (b *BareMetalPrinter) Data() [][]string { return [][]string{0: { b.BareMetal.ID, b.BareMetal.MainIP, - b.BareMetal.Tag, // nolint: staticcheck + b.BareMetal.Tag, //nolint: staticcheck strconv.Itoa(b.BareMetal.MacAddress), b.BareMetal.Label, b.BareMetal.Os, From 731e33d5f80687a595c8e9cc5ee56a160356d083 Mon Sep 17 00:00:00 2001 From: Paul Larsen Date: Mon, 26 Feb 2024 23:59:12 +0000 Subject: [PATCH 3/3] simplify NewPaging --- cmd/printer/printer.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/printer/printer.go b/cmd/printer/printer.go index a3a4a7ae..ac0715b3 100644 --- a/cmd/printer/printer.go +++ b/cmd/printer/printer.go @@ -128,11 +128,10 @@ func NewPagingFromMeta(m *govultr.Meta) *Paging { // NewPaging validates and initializes the paging data. func NewPaging(total int, next, prev string) *Paging { p := &Paging{ - Total: 0, + Total: total, CursorNext: emptyPlaceholder, CursorPrev: emptyPlaceholder, } - p.Total = total if next != "" { p.CursorNext = next