Skip to content

Commit

Permalink
cleanup, new table structure on print
Browse files Browse the repository at this point in the history
  • Loading branch information
undeadops committed Jul 23, 2018
1 parent cfdb4ff commit 740fab6
Show file tree
Hide file tree
Showing 10 changed files with 324 additions and 40 deletions.
7 changes: 7 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ builds:
- windows
goarch:
- amd64
- 386
- arm
- arm64
ignore:
- goos: openbsd
goarch: arm
goarm: 6
checksum:
# You can change the name of the checksums file.
# This is parsed with the Go template engine and the following variables
Expand Down
16 changes: 0 additions & 16 deletions Makefile

This file was deleted.

24 changes: 8 additions & 16 deletions ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ import (
"github.com/aws/aws-sdk-go-v2/aws/external"
"github.com/aws/aws-sdk-go-v2/service/ec2"

"github.com/fatih/color"
"github.com/gosuri/uitable"
"github.com/urfave/cli"
)

//{{$ec2.Name}}\t\t{{$ec2.state}}\t{{$ec2.id}}\t{{$ec2.role}}\t{{$ec2.cost_center}}\t{{$ec2.env}}\t{{$ec2.instancetype}}\t{{$ec2.ipaddress}}\t{{$ec2.publicIpaddress}}

func printEc2Instances(instances []map[string]string) error {
table := uitable.New()
table.AddRow("NAME", "ID", "STATE", "ROLE", "COST_CENTER", "IP Address", "PUBLIC ADDRESS", "AMI")
for _, i := range instances {
fmt.Printf(
"\x1b[33m%-25s\x1b[0m\t%-20s\t%-7s\t%-26s\t%-15s\t%-15s\t%-15s\t%-10s\n",
i["name"], i["id"], i["state"], i["role"], i["cost_center"], i["ipAddress"], i["publicIpAddress"], i["ami"])
table.AddRow(color.YellowString(i["name"]), i["id"], i["state"], i["role"], i["cost_center"], i["ipAddress"], i["publicIpAddress"], i["ami"])
}
fmt.Println(table)
return nil
}

func ec2List(c *cli.Context) error {
fmt.Println("EC2 List Instances")
fmt.Println("AWS Config Profile: ", awsProfile)

cfg, err := external.LoadDefaultAWSConfig(
external.WithSharedConfigProfile(awsProfile),
)
Expand All @@ -46,8 +46,8 @@ func ec2List(c *cli.Context) error {

req := svc.DescribeInstancesRequest(params)
resp, err := req.Send()
if err == nil {
fmt.Println("there was an error listing instances in", err.Error())
if err != nil {
fmt.Println("there was an error listing instances in", err)
log.Fatal(err.Error())
}

Expand All @@ -60,23 +60,15 @@ func ec2List(c *cli.Context) error {
for _, keys := range instances.Tags {
if *keys.Key == "Name" {
name = url.QueryEscape(*keys.Value)
} else {
name = "None"
}
if *keys.Key == "cost_center" {
costCenter = url.QueryEscape(*keys.Value)
} else {
costCenter = "Not Defined"
}
if *keys.Key == "env" {
env = url.QueryEscape(*keys.Value)
} else {
env = "unknown"
}
if *keys.Key == "role" {
role = url.QueryEscape(*keys.Value)
} else {
role = "Not Listed"
}
}

Expand Down
14 changes: 10 additions & 4 deletions elb.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@ import (
"github.com/aws/aws-sdk-go-v2/aws/awserr"
"github.com/aws/aws-sdk-go-v2/aws/external"
"github.com/aws/aws-sdk-go-v2/service/elb"
"github.com/gosuri/uitable"

"github.com/fatih/color"
"github.com/urfave/cli"
)

func printElb(elb []map[string]string) error {
table := uitable.New()
table.AddRow("NAME", "Members", "IN:OUT", "Availability", "DNS")
for _, e := range elb {
fmt.Printf(
"%-45s\t%-3s\t%-2s:%-2s\t%-15s\t%-50s\n",
color.YellowString(e["name"]), e["numInstances"], color.GreenString(e["instances_in"]),
color.RedString(e["instances_out"]), e["scheme"], e["dns"])
table.AddRow(color.YellowString(e["name"]),
e["numInstances"],
color.GreenString(e["instances_in"])+":"+color.RedString(e["instances_out"]),
e["scheme"],
e["dns"],
)
}
fmt.Println(table)
return nil
}

Expand Down
13 changes: 9 additions & 4 deletions rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ import (
"github.com/aws/aws-sdk-go-v2/aws/external"
"github.com/aws/aws-sdk-go-v2/service/rds"
"github.com/fatih/color"
"github.com/gosuri/uitable"
"github.com/urfave/cli"
)

func printRds(dbs []map[string]string) error {
table := uitable.New()
table.AddRow("NAME", "ENGINE", "VERSION", "IS_PUBLIC", "ENDPOINT")
for _, r := range dbs {
fmt.Printf(
"%-28s\t%s:%s\t%-18s\t%-50s\n",
color.YellowString(r["name"]), r["engine"], r["engine_version"],
r["isPublic"], r["endpoint"])
// fmt.Printf(
// "%-28s\t%s:%s\t%-18s\t%-50s\n",
// color.YellowString(r["name"]), r["engine"], r["engine_version"],
// r["isPublic"], r["endpoint"])
table.AddRow(color.YellowString(r["name"]), r["engine"], r["engine_version"], r["isPublic"], r["endpoint"])
}
fmt.Println(table)
return nil
}

Expand Down
10 changes: 10 additions & 0 deletions vendor/github.com/gosuri/uitable/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions vendor/github.com/gosuri/uitable/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions vendor/github.com/gosuri/uitable/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 740fab6

Please sign in to comment.