Skip to content

Commit cecbd88

Browse files
author
flowerinthenight
committed
Add flag in describe table.
1 parent 067e592 commit cecbd88

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

cmd/stack_describe.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func describe(cmd *cobra.Command, args []string) {
8686
}
8787

8888
w := tabwriter.NewWriter(os.Stdout, 0, 10, 5, ' ', 0)
89-
fmt.Fprintf(w, "INSTANCE ID\tINSTANCE TYPE\tINSTANCE MODEL\tPUBLIC DNS\tPUBLIC IP\tPRIVATE IP\tSTATUS\n")
89+
fmt.Fprintf(w, "INSTANCE ID\tINSTANCE TYPE\tINSTANCE MODEL\tPUBLIC DNS\tPUBLIC IP\tPRIVATE IP\tFLAG\tSTATUS\n")
9090
for _, inst := range stack.Instances {
9191
instype := "on-demand"
9292
if inst.InstanceLifecycle == "spot" {
@@ -108,18 +108,34 @@ func describe(cmd *cobra.Command, args []string) {
108108
pubip = strings.Join(ips.IpAddress, ",")
109109
}
110110

111+
// try to extract flag from key name
112+
flag := inst.KeyName
113+
if flag == "" {
114+
flag = inst.KeyPairName
115+
}
116+
117+
if flag != "" {
118+
parts := strings.Split(flag, "-")
119+
if len(parts) > 1 {
120+
flag = parts[len(parts)-1]
121+
} else {
122+
flag = ""
123+
}
124+
}
125+
111126
state := inst.State.Name
112127
if state == "" {
113128
state = fmt.Sprintf("%s", inst.Status)
114129
}
115130

116-
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
131+
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
117132
inst.InstanceId,
118133
instype,
119134
inst.InstanceType,
120135
inst.PublicDnsName,
121136
pubip,
122137
inst.PrivateIpAddress,
138+
flag,
123139
strings.ToLower(state))
124140
}
125141

0 commit comments

Comments
 (0)