Skip to content

Commit 1382bf1

Browse files
author
flowerinthenight
committed
Support for alicloud describe.
1 parent f7f6d10 commit 1382bf1

File tree

4 files changed

+102
-50
lines changed

4 files changed

+102
-50
lines changed

Gopkg.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/stack_describe.go

+51-10
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import (
55
"fmt"
66
"io/ioutil"
77
"os"
8+
"strings"
89
"text/tabwriter"
910

1011
"github.com/mobingi/mobingi-cli/pkg/cli"
1112
"github.com/mobingilabs/mobingi-sdk-go/mobingi/alm"
1213
"github.com/mobingilabs/mobingi-sdk-go/pkg/cmdline"
14+
d "github.com/mobingilabs/mobingi-sdk-go/pkg/debug"
1315
"github.com/mobingilabs/mobingi-sdk-go/pkg/pretty"
1416
"github.com/spf13/cobra"
1517
)
@@ -51,14 +53,6 @@ func describe(cmd *cobra.Command, args []string) {
5153
// we process `--fmt=raw` option first
5254
out := cli.GetCliStringFlag(cmd, "out")
5355
pfmt := cli.GetCliStringFlag(cmd, "fmt")
54-
/*
55-
if sess.Config.ApiVersion == 3 {
56-
if pfmt == "min" || pfmt == "" {
57-
pfmt = "json"
58-
}
59-
}
60-
*/
61-
6256
switch pfmt {
6357
case "raw":
6458
fmt.Println(string(body))
@@ -99,16 +93,63 @@ func describe(cmd *cobra.Command, args []string) {
9993
instype = inst.InstanceLifecycle
10094
}
10195

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+
102116
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\n",
103117
inst.InstanceId,
104118
instype,
105119
inst.InstanceType,
106-
inst.PublicIpAddress,
120+
pubip,
107121
inst.PrivateIpAddress,
108-
inst.State.Name)
122+
strings.ToLower(state))
109123
}
110124

125+
d.Info("[instances]")
111126
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\tFLAG\tCONTAINER\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+
}
112153
}
113154
}
114155
}

cmd/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func VersionCmd() *cobra.Command {
1212
Short: "print the version",
1313
Long: `Print the version.`,
1414
Run: func(cmd *cobra.Command, args []string) {
15-
fmt.Println("v1.0.3")
15+
fmt.Println("v1.0.4")
1616
},
1717
}
1818
}

vendor/github.com/mobingilabs/mobingi-sdk-go/mobingi/alm/types.go

+48-37
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)