...
1 package devstate
2
3 import (
4 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
5
6 "k8s.io/utils/pointer"
7 )
8
9 func GetGroup(command v1alpha2.Command) string {
10 if command.Exec != nil && command.Exec.Group != nil {
11 return string(command.Exec.Group.Kind)
12 }
13 if command.Apply != nil && command.Apply.Group != nil {
14 return string(command.Apply.Group.Kind)
15 }
16 if command.Composite != nil && command.Composite.Group != nil {
17 return string(command.Composite.Group.Kind)
18 }
19 return ""
20 }
21
22 func GetDefault(command v1alpha2.Command) bool {
23 if command.Exec != nil && command.Exec.Group != nil {
24 return pointer.BoolDeref(command.Exec.Group.IsDefault, false)
25 }
26 if command.Apply != nil && command.Apply.Group != nil {
27 return pointer.BoolDeref(command.Apply.Group.IsDefault, false)
28 }
29 if command.Composite != nil && command.Composite.Group != nil {
30 return pointer.BoolDeref(command.Composite.Group.IsDefault, false)
31 }
32 return false
33 }
34
35 func SetGroup(command *v1alpha2.Command, group string) {
36 if command.Exec != nil {
37 if group == "" {
38 command.Exec.Group = nil
39 return
40 }
41 if command.Exec.Group == nil {
42 command.Exec.Group = &v1alpha2.CommandGroup{}
43 }
44 command.Exec.Group.Kind = v1alpha2.CommandGroupKind(group)
45 return
46 }
47 if command.Apply != nil {
48 if group == "" {
49 command.Apply.Group = nil
50 return
51 }
52 if command.Apply.Group == nil {
53 command.Apply.Group = &v1alpha2.CommandGroup{}
54 }
55 command.Apply.Group.Kind = v1alpha2.CommandGroupKind(group)
56 return
57 }
58 if command.Composite != nil {
59 if group == "" {
60 command.Composite.Group = nil
61 return
62 }
63 if command.Composite.Group == nil {
64 command.Composite.Group = &v1alpha2.CommandGroup{}
65 }
66 command.Composite.Group.Kind = v1alpha2.CommandGroupKind(group)
67 return
68 }
69 }
70
71 func SetDefault(command *v1alpha2.Command, def bool) {
72 if command.Exec != nil {
73 if command.Exec.Group == nil {
74 command.Exec.Group = &v1alpha2.CommandGroup{}
75 }
76 command.Exec.Group.IsDefault = pointer.Bool(def)
77 return
78 }
79 if command.Apply != nil {
80 if command.Apply.Group == nil {
81 command.Apply.Group = &v1alpha2.CommandGroup{}
82 }
83 command.Apply.Group.IsDefault = pointer.Bool(def)
84 return
85 }
86 if command.Composite != nil {
87 if command.Composite.Group == nil {
88 command.Composite.Group = &v1alpha2.CommandGroup{}
89 }
90 command.Composite.Group.IsDefault = pointer.Bool(def)
91 return
92 }
93 }
94
View as plain text