-
Notifications
You must be signed in to change notification settings - Fork 69
/
bundle.go
85 lines (67 loc) · 1.68 KB
/
bundle.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
package recipes
import (
"fmt"
"github.com/newrelic/newrelic-cli/internal/install/execution"
)
type Bundle struct {
BundleRecipes []*BundleRecipe
Type BundleType
}
// OpenInstallationOperatingSystem - Operating System of target environment
type BundleType string
var BundleTypes = struct {
// MacOS operating system
CORE BundleType
// Linux-based operating system
ADDITIONALGUIDED BundleType
// Windows operating system
ADDITIONALTARGETED BundleType
}{
// MacOS operating system
CORE: "CORE",
// Linux-based operating system
ADDITIONALGUIDED: "ADDITIONALGUIDED",
// Windows operating system
ADDITIONALTARGETED: "ADDITIONALTARGETED",
}
func (b *Bundle) AddRecipe(bundleRecipe *BundleRecipe) {
if b.ContainsName(bundleRecipe.Recipe.Name) {
return
}
b.BundleRecipes = append(b.BundleRecipes, bundleRecipe)
}
func (b *Bundle) IsAdditionalGuided() bool {
return b.Type == BundleTypes.ADDITIONALGUIDED
}
func (b *Bundle) IsAdditionalTargeted() bool {
return b.Type == BundleTypes.ADDITIONALTARGETED
}
func (b *Bundle) ContainsName(name string) bool {
for i := range b.BundleRecipes {
if b.BundleRecipes[i].Recipe.Name == name {
return true
}
}
return false
}
func (b *Bundle) GetBundleRecipe(name string) *BundleRecipe {
for _, r := range b.BundleRecipes {
if r.Recipe.Name == name {
return r
}
}
return nil
}
func (b *Bundle) AvailableRecipeCount() int {
count := 0
for i := 0; i < len(b.BundleRecipes); i++ {
if b.BundleRecipes[i].HasStatus(execution.RecipeStatusTypes.AVAILABLE) {
count++
}
}
return count
}
func (b *Bundle) String() string {
result := fmt.Sprintf("%s %s", b.Type, b.BundleRecipes)
return fmt.Sprintf("{%s}", result)
}