...
1 package libdevfile
2
3 import (
4 "context"
5
6 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
7 "github.com/devfile/library/v2/pkg/devfile/parser"
8 "github.com/devfile/library/v2/pkg/devfile/parser/data/v2/common"
9 )
10
11
12 type applyCommand struct {
13 command v1alpha2.Command
14 devfileObj parser.DevfileObj
15 }
16
17 var _ command = (*applyCommand)(nil)
18
19
20 func newApplyCommand(devfileObj parser.DevfileObj, command v1alpha2.Command) *applyCommand {
21 return &applyCommand{
22 command: command,
23 devfileObj: devfileObj,
24 }
25 }
26
27 func (o *applyCommand) CheckValidity() error {
28 return nil
29 }
30
31 func (o *applyCommand) Execute(ctx context.Context, handler Handler, parentGroup *v1alpha2.CommandGroup) error {
32 devfileComponents, err := o.devfileObj.Data.GetComponents(common.DevfileOptions{
33 FilterByName: o.command.Apply.Component,
34 })
35 if err != nil {
36 return err
37 }
38
39 if len(devfileComponents) == 0 {
40 return NewComponentNotExistError(o.command.Apply.Component)
41 }
42
43 if len(devfileComponents) != 1 {
44 return NewComponentsWithSameNameError(o.command.Apply.Component)
45 }
46
47 component, err := newComponent(o.devfileObj, devfileComponents[0])
48 if err != nil {
49 return err
50 }
51
52 var kind v1alpha2.CommandGroupKind
53 if o.command.Apply.Group != nil {
54 kind = o.command.Apply.Group.Kind
55 }
56 if parentGroup != nil {
57 kind = parentGroup.Kind
58 }
59 return component.Apply(handler, kind)
60 }
61
View as plain text