/
template_describe.go
71 lines (58 loc) · 1.63 KB
/
template_describe.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package cmd
import (
"fmt"
"io/ioutil"
"github.com/mobingi/mobingi-cli/pkg/cli"
"github.com/mobingilabs/mobingi-sdk-go/mobingi/alm"
"github.com/mobingilabs/mobingi-sdk-go/pkg/cmdline"
"github.com/mobingilabs/mobingi-sdk-go/pkg/pretty"
"github.com/spf13/cobra"
)
func TemplateDescribeCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "describe",
Short: "describe a specific template version",
Long: `Describe a specific template version.
To get template version ids, you can use the command:
$ ` + cmdline.Args0() + ` template versions --id=foo
Example:
$ ` + cmdline.Args0() + ` template describe --id=foo --ver=bar`,
Run: tmplDescribe,
}
cmd.Flags().String("id", "", "stack id")
cmd.Flags().String("ver", "", "template version id, can be empty or 'latest'")
return cmd
}
func tmplDescribe(cmd *cobra.Command, args []string) {
sess, err := clisession()
cli.ErrorExit(err, 1)
svc := alm.New(sess)
in := &alm.DescribeTemplateInput{
StackId: cli.GetCliStringFlag(cmd, "id"),
VersionId: cli.GetCliStringFlag(cmd, "ver"),
}
resp, body, err := svc.DescribeTemplate(in)
cli.ErrorExit(err, 1)
exitOn401(resp)
out := cli.GetCliStringFlag(cmd, "out")
pfmt := cli.GetCliStringFlag(cmd, "fmt")
switch pfmt {
case "raw":
fmt.Println(string(body))
if out != "" {
err = ioutil.WriteFile(out, body, 0644)
cli.ErrorExit(err, 1)
}
default:
if pfmt == "json" || pfmt == "" {
indent := cli.GetCliIntFlag(cmd, "indent")
js := pretty.JSON(string(body), indent)
fmt.Println(js)
// write to file option
if out != "" {
err = ioutil.WriteFile(out, []byte(js), 0644)
cli.ErrorExit(err, 1)
}
}
}
}