This repository has been archived by the owner on Dec 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
client.go
84 lines (70 loc) 路 2.63 KB
/
client.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
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
// import (
// "fmt"
// "os"
// "reflect"
// "strings"
// "text/tabwriter"
// "gopkg.in/yaml.v2"
// api "github.com/toddproject/todd/api/exp"
// pb "github.com/toddproject/todd/api/exp/generated"
// )
// // PrintResourcesTable takes an API resource and pretty-prints it to a table, regardless of its fields.
// // use this for general resources that don't need any special output treatment.
// func PrintResourcesTable(resources []api.ToDDResource) error {
// w := new(tabwriter.Writer)
// // Format in tab-separated columns with a tab stop of 8.
// w.Init(os.Stdout, 0, 8, 0, '\t', 0)
// // print headers for the given resource (using the first one as a sample)
// headers, err := getResourceFields(resources[0])
// if err != nil {
// return err
// }
// fmt.Fprintln(w, strings.Join(headers, "\t"))
// // print values for each resource
// for i := range resources {
// values, err := getResourceValues(resources[i])
// if err != nil {
// return err
// }
// fmt.Fprintln(w, strings.Join(values, "\t"))
// }
// fmt.Fprintln(w)
// w.Flush()
// return nil
// }
// // getResourceFields retrieves a resource's field names and returns them as a slice of strings
// //
// // TODO (mierdin): Should consider just adding a field to each resource definition to keep track of the headers that are useful
// // in a list format. That way we don't have to do this reflect. print only the headers the object says are useful in a "list" operation
// // and print verbosely in a "get" operation, just like st2 does.
// func getResourceFields(resource api.ToDDResource) ([]string, error) {
// var retSlice []string
// val := reflect.ValueOf(resource).Elem()
// for i := 0; i < val.NumField(); i++ {
// typeField := val.Type().Field(i)
// retSlice = append(retSlice, strings.ToUpper(typeField.Name))
// }
// return retSlice, nil
// }
// // getResourceValues retrieves a resource's field values and returns them as a slice of strings
// func getResourceValues(resource api.ToDDResource) ([]string, error) {
// var retSlice []string
// val := reflect.ValueOf(resource).Elem()
// for i := 0; i < val.NumField(); i++ {
// // typeField := val.Type().Field(i)
// valueField := val.Field(i)
// retSlice = append(retSlice, fmt.Sprintf("%v", valueField.Interface()))
// }
// return retSlice, nil
// }
// // marshalGroupFromFile creates a new Group instance from a file definition
// func marshalGroupFromFile(absPath string) (*pb.Group, error) {
// yamlDef, _ := getYAMLDef(absPath)
// var groupObj *pb.Group
// err := yaml.Unmarshal(yamlDef, &groupObj)
// if err != nil {
// return nil, err
// }
// return groupObj, nil
// }