/
stat.go
42 lines (35 loc) · 830 Bytes
/
stat.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 main
import (
"fmt"
"os"
"text/tabwriter"
"github.com/evandbrown/dm/googlecloud"
"github.com/spf13/cobra"
)
var statCmd = &cobra.Command{
Use: "stat",
Short: "Stat a deployment, listing its resources",
}
func init() {
statCmd.PreRun = func(cmd *cobra.Command, args []string) {
requireName()
}
statCmd.Run = func(cmd *cobra.Command, args []string) {
Check(stat(cmd, args))
}
}
func stat(cmd *cobra.Command, args []string) error {
service, err := googlecloud.GetService()
Check(err)
call := service.Resources.List(Project, Name)
resources, error := call.Do()
Check(error)
w := new(tabwriter.Writer)
w.Init(os.Stdout, 0, 8, 2, '\t', 0)
fmt.Fprintln(w, "Resource Type\tName\t")
for _, r := range resources.Resources {
fmt.Fprintf(w, "%s\t%s\t\n", r.Type, r.Name)
}
w.Flush()
return nil
}