-
Notifications
You must be signed in to change notification settings - Fork 7
/
id.go
42 lines (36 loc) · 945 Bytes
/
id.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package cliaws
import (
"context"
"fmt"
"os"
"github.com/alexflint/go-arg"
"github.com/nathants/libaws/lib"
)
func init() {
lib.Commands["ec2-id"] = ec2Id
lib.Args["ec2-id"] = ec2IdArgs{}
}
type ec2IdArgs struct {
Selectors []string `arg:"positional" help:"instance-id | dns-name | private-dns-name | tag | vpc-id | subnet-id | security-group-id | ip-address | private-ip-address"`
State string `arg:"-s,--state" help:"running | pending | terminated | stopped" default:"running"`
}
func (ec2IdArgs) Description() string {
return "\nlist ec2 id\n"
}
func ec2Id() {
var args ec2IdArgs
arg.MustParse(&args)
ctx := context.Background()
instances, err := lib.EC2ListInstances(ctx, args.Selectors, args.State)
if err != nil {
lib.Logger.Fatal("error: ", err)
}
if len(instances) == 0 {
os.Exit(1)
}
for _, instance := range instances {
if instance.InstanceId != nil {
fmt.Println(*instance.InstanceId)
}
}
}