diff --git a/.goreleaser.yml b/.goreleaser.yml index d58f4ec..eb02d5f 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -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 diff --git a/Makefile b/Makefile deleted file mode 100644 index 137de71..0000000 --- a/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -default: build - -build: - GOOS=0 go build -o herd.darwin main.go - #GOOS=0 go build -ldflags "-X main.version ${rel} -X main.buildDate `date -u +.%Y%m%d%.H%M%S`" \ - -release: - @if git rev-parse -q --verify "refs/tags/$(ver)" >/dev/null; then \ - (echo "Building Release"); \ - /usr/local/bin/goreleaser; \ - else \ - (echo "Tag not found, creating then building release"); \ - git tag -a $(ver) -m "Building Release for Version $(ver)"; \ - git push origin $(ver); \ - /usr/local/bin/goreleaser; \ - fi diff --git a/ec2.go b/ec2.go index 9995da7..ce0c3b6 100644 --- a/ec2.go +++ b/ec2.go @@ -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), ) @@ -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()) } @@ -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" } } diff --git a/elb.go b/elb.go index 9c8ceb3..c858863 100644 --- a/elb.go +++ b/elb.go @@ -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 } diff --git a/rds.go b/rds.go index 048510b..11e9eec 100644 --- a/rds.go +++ b/rds.go @@ -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 } diff --git a/vendor/github.com/gosuri/uitable/LICENSE b/vendor/github.com/gosuri/uitable/LICENSE new file mode 100644 index 0000000..e436d90 --- /dev/null +++ b/vendor/github.com/gosuri/uitable/LICENSE @@ -0,0 +1,10 @@ +MIT License +=========== + +Copyright (c) 2015, Greg Osuri + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/github.com/gosuri/uitable/Makefile b/vendor/github.com/gosuri/uitable/Makefile new file mode 100644 index 0000000..60246a8 --- /dev/null +++ b/vendor/github.com/gosuri/uitable/Makefile @@ -0,0 +1,4 @@ +test: + @go test ./... + +.PHONY: test diff --git a/vendor/github.com/gosuri/uitable/README.md b/vendor/github.com/gosuri/uitable/README.md new file mode 100644 index 0000000..683b538 --- /dev/null +++ b/vendor/github.com/gosuri/uitable/README.md @@ -0,0 +1,67 @@ +# uitable [![GoDoc](https://godoc.org/github.com/gosuri/uitable?status.svg)](https://godoc.org/github.com/gosuri/uitable) [![Build Status](https://travis-ci.org/gosuri/uitable.svg?branch=master)](https://travis-ci.org/gosuri/uitable) + +uitable is a go library for representing data as tables for terminal applications. It provides primitives for sizing and wrapping columns to improve readability. + +## Example Usage + +Full source code for the example is available at [example/main.go](example/main.go) + +```go +table := uitable.New() +table.MaxColWidth = 50 + +table.AddRow("NAME", "BIRTHDAY", "BIO") +for _, hacker := range hackers { + table.AddRow(hacker.Name, hacker.Birthday, hacker.Bio) +} +fmt.Println(table) +``` + +Will render the data as: + +```sh +NAME BIRTHDAY BIO +Ada Lovelace December 10, 1815 Ada was a British mathematician and writer, chi... +Alan Turing June 23, 1912 Alan was a British pioneering computer scientis... +``` + +For wrapping in two columns: + +```go +table = uitable.New() +table.MaxColWidth = 80 +table.Wrap = true // wrap columns + +for _, hacker := range hackers { + table.AddRow("Name:", hacker.Name) + table.AddRow("Birthday:", hacker.Birthday) + table.AddRow("Bio:", hacker.Bio) + table.AddRow("") // blank +} +fmt.Println(table) +``` + +Will render the data as: + +``` +Name: Ada Lovelace +Birthday: December 10, 1815 +Bio: Ada was a British mathematician and writer, chiefly known for her work on + Charles Babbage's early mechanical general-purpose computer, the Analytical + Engine + +Name: Alan Turing +Birthday: June 23, 1912 +Bio: Alan was a British pioneering computer scientist, mathematician, logician, + cryptanalyst and theoretical biologist +``` + +## Installation + +``` +$ go get -v github.com/gosuri/uitable +``` + + +[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/gosuri/uitable/trend.png)](https://bitdeli.com/free "Bitdeli Badge") + diff --git a/vendor/github.com/gosuri/uitable/table.go b/vendor/github.com/gosuri/uitable/table.go new file mode 100644 index 0000000..b792c88 --- /dev/null +++ b/vendor/github.com/gosuri/uitable/table.go @@ -0,0 +1,203 @@ +// Package uitable provides a decorator for formating data as a table +package uitable + +import ( + "fmt" + "strings" + "sync" + + "github.com/gosuri/uitable/util/strutil" + "github.com/gosuri/uitable/util/wordwrap" + "github.com/mattn/go-runewidth" +) + +// Separator is the default column seperator +var Separator = "\t" + +// Table represents a decorator that renders the data in formatted in a table +type Table struct { + // Rows is the collection of rows in the table + Rows []*Row + + // MaxColWidth is the maximum allowed width for cells in the table + MaxColWidth uint + + // Wrap when set to true wraps the contents of the columns when the length exceeds the MaxColWidth + Wrap bool + + // Separator is the seperator for columns in the table. Default is "\t" + Separator string + + mtx *sync.RWMutex + rightAlign map[int]bool +} + +// New returns a new Table with default values +func New() *Table { + return &Table{ + Separator: Separator, + mtx: new(sync.RWMutex), + rightAlign: map[int]bool{}, + } +} + +// AddRow adds a new row to the table +func (t *Table) AddRow(data ...interface{}) *Table { + t.mtx.Lock() + defer t.mtx.Unlock() + r := NewRow(data...) + t.Rows = append(t.Rows, r) + return t +} + +// Bytes returns the []byte value of table +func (t *Table) Bytes() []byte { + return []byte(t.String()) +} + +func (t *Table) RightAlign(col int) { + t.mtx.Lock() + t.rightAlign[col] = true + t.mtx.Unlock() +} + +// String returns the string value of table +func (t *Table) String() string { + t.mtx.RLock() + defer t.mtx.RUnlock() + + if len(t.Rows) == 0 { + return "" + } + + // determine the width for each column (cell in a row) + var colwidths []uint + for _, row := range t.Rows { + for i, cell := range row.Cells { + // resize colwidth array + if i+1 > len(colwidths) { + colwidths = append(colwidths, 0) + } + cellwidth := cell.LineWidth() + if t.MaxColWidth != 0 && cellwidth > t.MaxColWidth { + cellwidth = t.MaxColWidth + } + + if cellwidth > colwidths[i] { + colwidths[i] = cellwidth + } + } + } + + var lines []string + for _, row := range t.Rows { + row.Separator = t.Separator + for i, cell := range row.Cells { + cell.Width = colwidths[i] + cell.Wrap = t.Wrap + cell.RightAlign = t.rightAlign[i] + } + lines = append(lines, row.String()) + } + return strutil.Join(lines, "\n") +} + +// Row represents a row in a table +type Row struct { + // Cells is the group of cell for the row + Cells []*Cell + + // Separator for tabular columns + Separator string +} + +// NewRow returns a new Row and adds the data to the row +func NewRow(data ...interface{}) *Row { + r := &Row{Cells: make([]*Cell, len(data))} + for i, d := range data { + r.Cells[i] = &Cell{Data: d} + } + return r +} + +// String returns the string representation of the row +func (r *Row) String() string { + // get the max number of lines for each cell + var lc int // line count + for _, cell := range r.Cells { + if clc := len(strings.Split(cell.String(), "\n")); clc > lc { + lc = clc + } + } + + // allocate a two-dimentional array of cells for each line and add size them + cells := make([][]*Cell, lc) + for x := 0; x < lc; x++ { + cells[x] = make([]*Cell, len(r.Cells)) + for y := 0; y < len(r.Cells); y++ { + cells[x][y] = &Cell{Width: r.Cells[y].Width} + } + } + + // insert each line in a cell as new cell in the cells array + for y, cell := range r.Cells { + lines := strings.Split(cell.String(), "\n") + for x, line := range lines { + cells[x][y].Data = line + } + } + + // format each line + lines := make([]string, lc) + for x := range lines { + line := make([]string, len(cells[x])) + for y := range cells[x] { + line[y] = cells[x][y].String() + } + lines[x] = strutil.Join(line, r.Separator) + } + return strutil.Join(lines, "\n") +} + +// Cell represents a column in a row +type Cell struct { + // Width is the width of the cell + Width uint + + // Wrap when true wraps the contents of the cell when the lenght exceeds the width + Wrap bool + + // RightAlign when true aligns contents to the right + RightAlign bool + + // Data is the cell data + Data interface{} +} + +// LineWidth returns the max width of all the lines in a cell +func (c *Cell) LineWidth() uint { + width := 0 + for _, s := range strings.Split(c.String(), "\n") { + w := runewidth.StringWidth(s) + if w > width { + width = w + } + } + return uint(width) +} + +// String returns the string formated representation of the cell +func (c *Cell) String() string { + if c.Data == nil { + return strutil.PadLeft(" ", int(c.Width), ' ') + } + s := fmt.Sprintf("%v", c.Data) + if c.Width > 0 { + if c.Wrap && uint(len(s)) > c.Width { + return wordwrap.WrapString(s, c.Width) + } else { + return strutil.Resize(s, c.Width, c.RightAlign) + } + } + return s +} diff --git a/vendor/vendor.json b/vendor/vendor.json index 1cd9747..89091aa 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -49,6 +49,12 @@ "revision": "99ff426eb706cffe92ff3d058e168b278cabf7c7", "revisionTime": "2018-07-19T07:19:42Z" }, + { + "checksumSHA1": "cACEkFM7kIL+NVF6jSJPY2tW4d8=", + "path": "github.com/gosuri/uitable", + "revision": "36ee7e946282a3fb1cfecd476ddc9b35d8847e42", + "revisionTime": "2016-04-04T20:39:58Z" + }, { "checksumSHA1": "l2CJX8X2+faB4Ja9jUaOFNdrzY0=", "path": "github.com/gucumber/gucumber",