/
workspace_resources.go
61 lines (52 loc) · 1.48 KB
/
workspace_resources.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
package modconfig
import "sort"
// WorkspaceResources is used exclusively for the query/check command completion
// TODO to be refactored
type WorkspaceResources struct {
Query map[string]bool
Control map[string]bool
Benchmark map[string]bool
}
func NewWorkspaceResources() *WorkspaceResources {
return &WorkspaceResources{
Query: make(map[string]bool),
Control: make(map[string]bool),
Benchmark: make(map[string]bool),
}
}
func (r *WorkspaceResources) Merge(other *WorkspaceResources) *WorkspaceResources {
for k := range other.Query {
r.Query[k] = true
}
for k := range other.Control {
r.Control[k] = true
}
for k := range other.Benchmark {
r.Benchmark[k] = true
}
return r
}
// GetSortedBenchmarksAndControlNames gives back a list of the benchmarks
// and controls in the current workspace.
// The list is sorted alphabetically - with the benchmarks first
func (w *WorkspaceResources) GetSortedBenchmarksAndControlNames() []string {
benchmarkList := []string{}
controlList := []string{}
for key := range w.Benchmark {
benchmarkList = append(benchmarkList, key)
}
for key := range w.Control {
controlList = append(controlList, key)
}
sort.Strings(benchmarkList)
sort.Strings(controlList)
return append(benchmarkList, controlList...)
}
func (w *WorkspaceResources) GetSortedNamedQueryNames() []string {
namedQueries := []string{}
for key := range w.Query {
namedQueries = append(namedQueries, key)
}
sort.Strings(namedQueries)
return namedQueries
}