Skip to content

Commit e8605c3

Browse files
committed
adding extra details to search output. formating table view
1 parent 7eaf8cc commit e8605c3

3 files changed

Lines changed: 22 additions & 18 deletions

File tree

Makefile

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
TEST?=./...
22
NAME = $(shell awk -F\" '/^const Name/ { print $$2 }' main.go)
33
VERSION = $(shell awk -F\" '/^const Version/ { print $$2 }' main.go)
4-
DEPS = $(shell go list -f '{{range .TestImports}}{{.}} {{end}}' ./...)
54

6-
all: deps build
7-
8-
deps:
9-
go get -d -v ./...
10-
echo $(DEPS) | xargs -n1 go get -d
11-
12-
updatedeps:
13-
go get -u -v ./...
14-
echo $(DEPS) | xargs -n1 go get -d
5+
all: build
156

167
build: deps
178
@mkdir -p bin/
@@ -34,4 +25,4 @@ package: xcompile
3425
echo $$f; \
3526
done
3627

37-
.PHONY: all deps updatedeps build xcompile package
28+
.PHONY: all deps build xcompile package

instance.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ package main
33
import (
44
"fmt"
55
"log"
6-
7-
"github.com/awslabs/aws-sdk-go/service/ec2"
86
"github.com/mitchellh/go-homedir"
7+
"github.com/awslabs/aws-sdk-go/service/ec2"
98
)
109

1110
//ec2 instance type
@@ -16,6 +15,8 @@ type Instance struct {
1615
Name string
1716
Port string
1817
BaseKeyPath string
18+
State string
19+
Type string
1920
}
2021

2122
func (i Instance) KeyPath() string {
@@ -43,6 +44,7 @@ func InstancesFromReservations(reservations []*ec2.Reservation, keyPath string)
4344
user := "ubuntu"
4445
key := ""
4546
host := ""
47+
state := *inst.State.Name
4648
for _, keys := range inst.Tags {
4749
if *keys.Key == "Name" {
4850
name = *keys.Value
@@ -64,6 +66,7 @@ func InstancesFromReservations(reservations []*ec2.Reservation, keyPath string)
6466
Host: host,
6567
Key: key,
6668
BaseKeyPath: keyPath,
69+
State: state,
6770
})
6871
}
6972
}

main.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ import (
1515
"github.com/awslabs/aws-sdk-go/aws"
1616
"github.com/awslabs/aws-sdk-go/service/ec2"
1717
"github.com/codegangsta/cli"
18+
"github.com/olekukonko/tablewriter"
1819
)
1920

2021
// Name is the exported name of this application.
2122
const Name = "aws-ssh"
2223

2324
// Version is the current version of this application.
24-
const Version = "0.0.2.dev"
25+
const Version = "0.0.3.dev"
2526

2627
func main() {
2728
app := cli.NewApp()
@@ -157,10 +158,8 @@ func selectInstance(server string, instances []Instance) (Instance, error) {
157158
return matches[0], nil
158159
}
159160
fmt.Println("Found ", len(matches), "matches in", len(instances), "instances")
160-
for pos, match := range matches {
161-
fmt.Println(pos, " ", match.Name)
162-
}
163-
fmt.Print("Select vm: ")
161+
writeInstances(matches)
162+
fmt.Print("Select vm Num : ")
164163
var input string
165164
fmt.Scanln(&input)
166165
fmt.Print(input)
@@ -172,6 +171,17 @@ func selectInstance(server string, instances []Instance) (Instance, error) {
172171

173172
}
174173

174+
func writeInstances(matches []Instance){
175+
table := tablewriter.NewWriter(os.Stdout)
176+
table.SetHeader([]string{"Num", "Name", "State", "IP"})
177+
178+
for pos, match := range matches {
179+
table.Append([]string{ strconv.Itoa(pos), match.Name, match.State, match.Host})
180+
// fmt.Println(pos, " ", match.Name, " ", match.State, " ", match.Host)
181+
}
182+
table.Render()
183+
}
184+
175185
func shell(inst Instance) {
176186
remoteServer := inst.Host
177187
if inst.User != "" {

0 commit comments

Comments
 (0)