Skip to content

Commit

Permalink
Minor changes to match flow of lb list and certificate list
Browse files Browse the repository at this point in the history
- Inline display function
- Match order of functions
  • Loading branch information
jpignata committed Feb 27, 2018
1 parent 7a5983c commit 450ebeb
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 57 deletions.
41 changes: 20 additions & 21 deletions cmd/certificate_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,26 @@ func (o certificateListOperation) execute() {
return
}

o.display(certificates)
rows := [][]string{
[]string{"CERTIFICATE", "TYPE", "STATUS", "SUBJECT ALTERNATIVE NAMES"},
}

sort.Slice(certificates, func(i, j int) bool {
return certificates[i].DomainName < certificates[j].DomainName
})

for _, certificate := range certificates {
rows = append(rows,
[]string{
certificate.DomainName,
Titleize(certificate.Type),
Titleize(certificate.Status),
strings.Join(certificate.SubjectAlternativeNames, ", "),
},
)
}

o.output.Table("", rows)
}

func (o certificateListOperation) find() (acm.Certificates, error) {
Expand Down Expand Up @@ -75,26 +94,6 @@ func (o certificateListOperation) find() (acm.Certificates, error) {
}

func (o certificateListOperation) display(certificates []acm.Certificate) {
rows := [][]string{
[]string{"CERTIFICATE", "TYPE", "STATUS", "SUBJECT ALTERNATIVE NAMES"},
}

sort.Slice(certificates, func(i, j int) bool {
return certificates[i].DomainName < certificates[j].DomainName
})

for _, certificate := range certificates {
rows = append(rows,
[]string{
certificate.DomainName,
Titleize(certificate.Type),
Titleize(certificate.Status),
strings.Join(certificate.SubjectAlternativeNames, ", "),
},
)
}

o.output.Table("", rows)
}

var certificateListCmd = &cobra.Command{
Expand Down
72 changes: 36 additions & 36 deletions cmd/lb_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,42 @@ type lbListOperation struct {
output Output
}

func (o lbListOperation) execute() {
loadBalancers, err := o.find()

if err != nil {
o.output.Fatal(err, "Could not list load balancers")
return
}

if len(loadBalancers) == 0 {
o.output.Info("No load balancers found")
return
}

rows := [][]string{
[]string{"NAME", "TYPE", "STATUS", "DNS NAME", "PORTS"},
}

sort.Slice(loadBalancers, func(i, j int) bool {
return loadBalancers[i].Name < loadBalancers[j].Name
})

for _, loadBalancer := range loadBalancers {
rows = append(rows,
[]string{
loadBalancer.Name,
Titleize(loadBalancer.Type),
Titleize(loadBalancer.Status),
loadBalancer.DNSName,
fmt.Sprintf("%s", loadBalancer.Listeners),
},
)
}

o.output.Table("", rows)
}

func (o lbListOperation) find() (elbv2.LoadBalancers, error) {
var wg sync.WaitGroup

Expand Down Expand Up @@ -62,42 +98,6 @@ func (o lbListOperation) find() (elbv2.LoadBalancers, error) {
}
}

func (o lbListOperation) execute() {
loadBalancers, err := o.find()

if err != nil {
o.output.Fatal(err, "Could not list load balancers")
return
}

if len(loadBalancers) == 0 {
o.output.Info("No load balancers found")
return
}

sort.Slice(loadBalancers, func(i, j int) bool {
return loadBalancers[i].Name < loadBalancers[j].Name
})

rows := [][]string{
[]string{"NAME", "TYPE", "STATUS", "DNS NAME", "PORTS"},
}

for _, loadBalancer := range loadBalancers {
rows = append(rows,
[]string{
loadBalancer.Name,
Titleize(loadBalancer.Type),
Titleize(loadBalancer.Status),
loadBalancer.DNSName,
fmt.Sprintf("%s", loadBalancer.Listeners),
},
)
}

o.output.Table("", rows)
}

var lbListCmd = &cobra.Command{
Use: "list",
Short: "List load balancers",
Expand Down

0 comments on commit 450ebeb

Please sign in to comment.