forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
componentmatch.go
102 lines (87 loc) · 2.6 KB
/
componentmatch.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package app
import (
imageapi "github.com/openshift/origin/pkg/image/api"
templateapi "github.com/openshift/origin/pkg/template/api"
)
// ComponentMatch is a match to a provided component
type ComponentMatch struct {
// what this is a match for (the value that was searched on)
Value string
// the argument to use to specify this match explicitly
Argument string
// the exact name of this match
Name string
Description string
Score float32
Insecure bool
LocalOnly bool
NoTagsFound bool
// this match represents a scratch image, there is no
// actual image/pullspec.
Virtual bool
// The source of the match. Generally only a single source is
// available.
Image *imageapi.DockerImage
ImageStream *imageapi.ImageStream
ImageTag string
Template *templateapi.Template
// Input to generators extracted from the source
Builder bool
GeneratorInput GeneratorInput
// TODO: remove me
Meta map[string]string
}
func (m *ComponentMatch) String() string {
return m.Argument
}
// IsImage returns whether or not the component match is an
// image or image stream
func (m *ComponentMatch) IsImage() bool {
return m.Template == nil
}
// IsTemplate returns whether or not the component match is
// a template
func (m *ComponentMatch) IsTemplate() bool {
return m.Template != nil
}
// Exact checks if the ComponentMatch is an exact match
func (m *ComponentMatch) Exact() bool {
return m.Score == 0.0
}
// ComponentMatches holds multiple ComponentMatch
type ComponentMatches []*ComponentMatch
// Exact returns all ComponentMatch that are an exact match
func (m ComponentMatches) Exact() ComponentMatches {
exact := ComponentMatches{}
for _, match := range m {
if match.Exact() {
exact = append(exact, match)
}
}
return exact
}
// Inexact returns all ComponentMatch that are not an exact match
func (m ComponentMatches) Inexact() ComponentMatches {
inexact := ComponentMatches{}
for _, match := range m {
if !match.Exact() {
inexact = append(inexact, match)
}
}
return inexact
}
// ScoredComponentMatches is a set of component matches grouped by score
type ScoredComponentMatches []*ComponentMatch
func (m ScoredComponentMatches) Len() int { return len(m) }
func (m ScoredComponentMatches) Swap(i, j int) { m[i], m[j] = m[j], m[i] }
func (m ScoredComponentMatches) Less(i, j int) bool { return m[i].Score < m[j].Score }
// Exact returns all the exact component matches
func (m ScoredComponentMatches) Exact() []*ComponentMatch {
out := []*ComponentMatch{}
for _, match := range m {
if match.Score == 0.0 {
out = append(out, match)
}
}
return out
}