@@ -5,11 +5,13 @@ import (
5
5
"fmt"
6
6
"io/ioutil"
7
7
"os"
8
+ "strings"
8
9
"text/tabwriter"
9
10
10
11
"github.com/mobingi/mobingi-cli/pkg/cli"
11
12
"github.com/mobingilabs/mobingi-sdk-go/mobingi/alm"
12
13
"github.com/mobingilabs/mobingi-sdk-go/pkg/cmdline"
14
+ d "github.com/mobingilabs/mobingi-sdk-go/pkg/debug"
13
15
"github.com/mobingilabs/mobingi-sdk-go/pkg/pretty"
14
16
"github.com/spf13/cobra"
15
17
)
@@ -51,14 +53,6 @@ func describe(cmd *cobra.Command, args []string) {
51
53
// we process `--fmt=raw` option first
52
54
out := cli .GetCliStringFlag (cmd , "out" )
53
55
pfmt := cli .GetCliStringFlag (cmd , "fmt" )
54
- /*
55
- if sess.Config.ApiVersion == 3 {
56
- if pfmt == "min" || pfmt == "" {
57
- pfmt = "json"
58
- }
59
- }
60
- */
61
-
62
56
switch pfmt {
63
57
case "raw" :
64
58
fmt .Println (string (body ))
@@ -99,16 +93,63 @@ func describe(cmd *cobra.Command, args []string) {
99
93
instype = inst .InstanceLifecycle
100
94
}
101
95
96
+ pubip := string (inst .PublicIpAddress )
97
+ pubip = strings .TrimLeft (pubip , "\" " )
98
+ pubip = strings .TrimRight (pubip , "\" " )
99
+
100
+ // try if ip is json (alicloud)
101
+ type pubip_t struct {
102
+ IpAddress []string
103
+ }
104
+
105
+ var ips pubip_t
106
+ err = json .Unmarshal (inst .PublicIpAddress , & ips )
107
+ if err == nil {
108
+ pubip = strings .Join (ips .IpAddress , "," )
109
+ }
110
+
111
+ state := inst .State .Name
112
+ if state == "" {
113
+ state = fmt .Sprintf ("%s" , inst .Status )
114
+ }
115
+
102
116
fmt .Fprintf (w , "%s\t %s\t %s\t %s\t %s\t %s\n " ,
103
117
inst .InstanceId ,
104
118
instype ,
105
119
inst .InstanceType ,
106
- inst . PublicIpAddress ,
120
+ pubip ,
107
121
inst .PrivateIpAddress ,
108
- inst . State . Name )
122
+ strings . ToLower ( state ) )
109
123
}
110
124
125
+ d .Info ("[instances]" )
111
126
w .Flush ()
127
+ fmt .Println ()
128
+
129
+ // separate table for configurations, if any
130
+ if stack .Configuration .Configurations != nil {
131
+ w = tabwriter .NewWriter (os .Stdout , 0 , 10 , 5 , ' ' , 0 )
132
+ fmt .Fprintf (w , "ROLE\t FLAG\t CONTAINER\n " )
133
+
134
+ var (
135
+ cnfs []alm.Configurations
136
+ contnr bool
137
+ )
138
+
139
+ err = json .Unmarshal (stack .Configuration .Configurations , & cnfs )
140
+ cli .ErrorExit (err , 1 )
141
+
142
+ for _ , inst := range cnfs {
143
+ if inst .Container != nil {
144
+ contnr = true
145
+ }
146
+
147
+ fmt .Fprintf (w , "%s\t %s\t %v\n " , inst .Role , inst .Flag , contnr )
148
+ }
149
+
150
+ d .Info ("[configurations]" )
151
+ w .Flush ()
152
+ }
112
153
}
113
154
}
114
155
}
0 commit comments