/
targets_list.go
76 lines (66 loc) · 1.95 KB
/
targets_list.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
package cmd
import (
"github.com/cheynewallace/tabby"
"github.com/myfintech/ark/src/go/lib/pattern"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/myfintech/ark/src/go/lib/arksdk/target/base"
)
var targetsListCmd = &cobra.Command{
Use: "list",
Short: "list is a sub-command of targets that lists all buildable targets",
RunE: func(cmd *cobra.Command, args []string) error {
var matcher *pattern.Matcher
t := tabby.New()
t.AddHeader("short_hash", "target_address", "locally_cached", "remotely_cached", "labels", "description")
remote, err := cmd.Flags().GetBool("remote")
if err != nil {
return err
}
patterns, err := cmd.Flags().GetStringSlice("filters")
if err != nil {
return err
}
if len(patterns) > 0 {
matcher = &pattern.Matcher{
Includes: patterns,
}
if err = matcher.Compile(); err != nil {
return err
}
}
for _, address := range workspace.TargetLUT.FilterSortedAddresses(matcher) {
addressable := workspace.TargetLUT[address]
buildableTarget, buildable := addressable.(base.Buildable)
cacheableTarget, cacheable := addressable.(base.Cacheable)
locallyCached := false
remotelyCached := false
if buildable {
if err = buildableTarget.PreBuild(); err != nil {
return err
}
}
if cacheable {
locallyCached, err = cacheableTarget.CheckLocalBuildCache()
if err != nil {
return err
}
if remote {
remotelyCached, err = cacheableTarget.CheckRemoteCache()
if err != nil {
return err
}
}
}
t.AddLine(buildableTarget.ShortHash(), address, locallyCached, remotelyCached, buildableTarget.ListLabels(), addressable.Describe())
}
t.Print()
return nil
},
}
func init() {
targetsCmd.AddCommand(targetsListCmd)
_ = targetsListCmd.Flags().Bool("remote", false, "check remote cache")
_ = targetsListCmd.Flags().StringSlice("filters", nil, "filters used to limit list results")
_ = viper.BindPFlags(targetsCmd.PersistentFlags())
}