Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework the printer output code #355

Merged
merged 3 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,11 @@ issues:
# Default: https://golangci-lint.run/usage/false-positives/#default-exclusions
exclude:
- abcdef
- ST1023
exclude-rules:
# Exclude some linters from running on tests files.
- path: cmd/printer/
linters:
- funlen
- gocyclo
- dupl
- lll
- gomnd
- gocritic
- stylecheck

run:
timeout: 5m
6 changes: 3 additions & 3 deletions cmd/dnsRecord.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ var recordCreate = &cobra.Command{
os.Exit(1)
}

printer.DnsRecord(record)
printer.DNSRecord(record)
},
}

Expand All @@ -139,7 +139,7 @@ var recordGet = &cobra.Command{
os.Exit(1)
}

printer.DnsRecord(record)
printer.DNSRecord(record)
},
}

Expand All @@ -163,7 +163,7 @@ var recordList = &cobra.Command{
os.Exit(1)
}

printer.DnsRecordsList(records, meta)
printer.DNSRecordsList(records, meta)
},
}

Expand Down
15 changes: 11 additions & 4 deletions cmd/printer/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ import (
)

func Account(account *govultr.Account) {
col := columns{"BALANCE", "PENDING CHARGES", "LAST PAYMENT DATE", "LAST PAYMENT AMOUNT", "NAME", "EMAIL", "ACLS"}
display(col)
display(columns{account.Balance, account.PendingCharges, account.LastPaymentDate, account.LastPaymentAmount, account.Name, account.Email, account.ACL})
flush()
defer flush()
display(columns{"BALANCE", "PENDING CHARGES", "LAST PAYMENT DATE", "LAST PAYMENT AMOUNT", "NAME", "EMAIL", "ACLS"})
display(columns{
account.Balance,
account.PendingCharges,
account.LastPaymentDate,
account.LastPaymentAmount,
account.Name,
account.Email,
account.ACL,
})
}
25 changes: 20 additions & 5 deletions cmd/printer/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,27 @@ import (
)

func Application(apps []govultr.Application, meta *govultr.Meta) {
col := columns{"ID", "NAME", "SHORT NAME", "DEPLOY NAME", "TYPE", "VENDOR", "IMAGE ID"}
display(col)
for _, a := range apps {
display(columns{a.ID, a.Name, a.ShortName, a.DeployName, a.Type, a.Vendor, a.ImageID})
defer flush()

display(columns{"ID", "NAME", "SHORT NAME", "DEPLOY NAME", "TYPE", "VENDOR", "IMAGE ID"})

if len(apps) == 0 {
display(columns{"---", "---", "---", "---", "---", "---", "---"})
Meta(meta)
return
}

for i := range apps {
display(columns{
apps[i].ID,
apps[i].Name,
apps[i].ShortName,
apps[i].DeployName,
apps[i].Type,
apps[i].Vendor,
apps[i].ImageID,
})
}

Meta(meta)
flush()
}
29 changes: 21 additions & 8 deletions cmd/printer/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,32 @@ import (
)

func Backups(bs []govultr.Backup, meta *govultr.Meta) {
col := columns{"ID", "DATE CREATED", "DESCRIPTION", "SIZE", "STATUS"}
display(col)
for _, b := range bs {
display(columns{b.ID, b.DateCreated, b.Description, b.Size, b.Status})
defer flush()

display(columns{"ID", "DATE CREATED", "DESCRIPTION", "SIZE", "STATUS"})

if len(bs) == 0 {
display(columns{"---", "---", "---", "---", "---"})
Meta(meta)
return
}

for i := range bs {
display(columns{
bs[i].ID,
bs[i].DateCreated,
bs[i].Description,
bs[i].Size,
bs[i].Status,
})
}

Meta(meta)
flush()
}

func Backup(bs *govultr.Backup) {
col := columns{"ID", "DATE CREATED", "DESCRIPTION", "SIZE", "STATUS"}
display(col)
defer flush()

flush()
display(columns{"ID", "DATE CREATED", "DESCRIPTION", "SIZE", "STATUS"})
display(columns{bs.ID, bs.DateCreated, bs.Description, bs.Size, bs.Status})
}
111 changes: 88 additions & 23 deletions cmd/printer/bareMetal.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,65 +5,130 @@ import (
)

func BareMetal(b *govultr.BareMetalServer) {
col := columns{"ID", "IP", "TAG", "MAC ADDRESS", "LABEL", "OS", "STATUS", "REGION", "CPU", "RAM", "DISK", "FEATURES", "TAGS"}
display(col)
defer flush()

display(columns{"ID", "IP", "TAG", "MAC ADDRESS", "LABEL", "OS", "STATUS", "REGION", "CPU", "RAM", "DISK", "FEATURES", "TAGS"})
display(columns{b.ID, b.MainIP, b.Tag, b.MacAddress, b.Label, b.Os, b.Status, b.Region, b.CPUCount, b.RAM, b.Disk, b.Features, b.Tags}) //nolint:all

flush()
}

func BareMetalList(bms []govultr.BareMetalServer, meta *govultr.Meta) {
col := columns{"ID", "IP", "TAG", "MAC ADDRESS", "LABEL", "OS", "STATUS", "REGION", "CPU", "RAM", "DISK", "FEATURES", "TAGS"}
display(col)
for _, b := range bms {
display(columns{b.ID, b.MainIP, b.Tag, b.MacAddress, b.Label, b.Os, b.Status, b.Region, b.CPUCount, b.RAM, b.Disk, b.Features, b.Tags}) //nolint:all
defer flush()

display(columns{"ID", "IP", "TAG", "MAC ADDRESS", "LABEL", "OS", "STATUS", "REGION", "CPU", "RAM", "DISK", "FEATURES", "TAGS"})

if len(bms) == 0 {
display(columns{"---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---"})
Meta(meta)
return
}

Meta(meta)
for i := range bms {
display(columns{
bms[i].ID,
bms[i].MainIP,
bms[i].MacAddress,
bms[i].Label,
bms[i].Os,
bms[i].Status,
bms[i].Region,
bms[i].CPUCount,
bms[i].RAM,
bms[i].Disk,
bms[i].Features,
bms[i].Tags,
})
}

flush()
Meta(meta)
}

func BareMetalBandwidth(bw *govultr.Bandwidth) {
defer flush()

display(columns{"DATE", "INCOMING BYTES", "OUTGOING BYTES"})
for k, b := range bw.Bandwidth {
display(columns{k, b.IncomingBytes, b.OutgoingBytes})
if len(bw.Bandwidth) == 0 {
display(columns{"---", "---", "---"})
return
}

for i := range bw.Bandwidth {
display(columns{
i,
bw.Bandwidth[i].IncomingBytes,
bw.Bandwidth[i].OutgoingBytes,
})
}
flush()
}

func BareMetalIPV4Info(info []govultr.IPv4, meta *govultr.Meta) {
defer flush()

display(columns{"IP", "NETMASK", "GATEWAY", "TYPE"})
for _, i := range info {
display(columns{i.IP, i.Netmask, i.Gateway, i.Type})

if len(info) == 0 {
display(columns{"---", "---", "---", "---"})
Meta(meta)
return
}

for i := range info {
display(columns{
info[i].IP,
info[i].Netmask,
info[i].Gateway,
info[i].Type,
})
}

Meta(meta)
flush()
}

func BareMetalIPV6Info(info []govultr.IPv6, meta *govultr.Meta) {
defer flush()

display(columns{"IP", "NETWORK", "NETWORK SIZE", "TYPE"})
for _, i := range info {
display(columns{i.IP, i.Network, i.NetworkSize, i.Type})

if len(info) == 0 {
display(columns{"---", "---", "---", "---"})
Meta(meta)
return
}

for i := range info {
display(columns{
info[i].IP,
info[i].Network,
info[i].NetworkSize,
info[i].Type,
})
}

Meta(meta)
flush()
}

func BareMetalVNCUrl(vnc *govultr.VNCUrl) {
defer flush()

display(columns{"VNC URL"})
display(columns{vnc.URL})
flush()
}

// BareMetalVPC2List Generate a printer display of all VPC 2.0 networks attached to a given server
func BareMetalVPC2List(vpc2s []govultr.VPC2Info) {
defer flush()

display(columns{"ID", "MAC ADDRESS", "IP ADDRESS"})
for _, r := range vpc2s {
display(columns{r.ID, r.MacAddress, r.IPAddress})

if len(vpc2s) == 0 {
display(columns{"---", "---", "---"})
return
}

for i := range vpc2s {
display(columns{
vpc2s[i].ID,
vpc2s[i].MacAddress,
vpc2s[i].IPAddress,
})
}
flush()
}
77 changes: 60 additions & 17 deletions cmd/printer/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,84 @@ import (
)

func BillingHistory(bh []govultr.History, meta *govultr.Meta) {
col := columns{"ID", "DATE", "TYPE", "DESCRIPTION", "AMOUNT", "BALANCE"}
display(col)
for _, b := range bh {
display(columns{b.ID, b.Date, b.Type, b.Description, b.Amount, b.Balance})
defer flush()

display(columns{"ID", "DATE", "TYPE", "DESCRIPTION", "AMOUNT", "BALANCE"})

if len(bh) == 0 {
display(columns{"---", "---", "---", "---", "---", "---"})
Meta(meta)
return
}

for i := range bh {
display(columns{
bh[i].ID,
bh[i].Date,
bh[i].Type,
bh[i].Description,
bh[i].Amount,
bh[i].Balance,
})
}

Meta(meta)
flush()
}

func Invoices(inv []govultr.Invoice, meta *govultr.Meta) {
col := columns{"ID", "DATE", "DESCRIPTION", "AMOUNT", "BALANCE"}
display(col)
for _, i := range inv {
display(columns{i.ID, i.Date, i.Description, i.Amount, i.Balance})
defer flush()

display(columns{"ID", "DATE", "DESCRIPTION", "AMOUNT", "BALANCE"})

if len(inv) == 0 {
display(columns{"---", "---", "---", "---", "---"})
Meta(meta)
return
}

for i := range inv {
display(columns{
inv[i].ID,
inv[i].Date,
inv[i].Description,
inv[i].Amount,
inv[i].Balance,
})
}

Meta(meta)
flush()
}

func Invoice(i *govultr.Invoice) {
defer flush()

display(columns{"ID", "DATE", "DESCRIPTION", "AMOUNT", "BALANCE"})
display(columns{i.ID, i.Date, i.Description, i.Amount, i.Balance})

flush()
}

func InvoiceItems(inv []govultr.InvoiceItem, meta *govultr.Meta) {
col := columns{"DESCRIPTION", "PRODUCT", "START DATE", "END DATE", "UNITS", "UNIT TYPE", "UNIT PRICE", "TOTAL"}
display(col)
for _, i := range inv {
display(columns{i.Description, i.Product, i.StartDate, i.EndDate, i.Units, i.UnitType, i.UnitPrice, i.Total})
defer flush()

display(columns{"DESCRIPTION", "PRODUCT", "START DATE", "END DATE", "UNITS", "UNIT TYPE", "UNIT PRICE", "TOTAL"})

if len(inv) == 0 {
display(columns{"---", "---", "---", "---", "---", "---", "---", "---"})
Meta(meta)
return
}

for i := range inv {
display(columns{
inv[i].Description,
inv[i].Product,
inv[i].StartDate,
inv[i].EndDate,
inv[i].Units,
inv[i].UnitType,
inv[i].UnitPrice,
inv[i].Total,
})
}

Meta(meta)
flush()
}
Loading