...
1 package generator
2
3 import (
4 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
5 "github.com/devfile/api/v2/pkg/attributes"
6 )
7
8 type CompositeCommandParams struct {
9 Id string
10 Attributes *attributes.Attributes
11
12 Commands []string
13 Parallel *bool
14
15 Label *string
16 Kind v1alpha2.CommandGroupKind
17 IsDefault *bool
18 }
19
20 func GetCompositeCommand(params CompositeCommandParams) v1alpha2.Command {
21 cmd := v1alpha2.Command{
22 Id: params.Id,
23 CommandUnion: v1alpha2.CommandUnion{
24 Composite: &v1alpha2.CompositeCommand{
25 LabeledCommand: v1alpha2.LabeledCommand{
26 BaseCommand: v1alpha2.BaseCommand{
27 Group: &v1alpha2.CommandGroup{
28 Kind: params.Kind,
29 IsDefault: params.IsDefault,
30 },
31 },
32 },
33 Commands: params.Commands,
34 Parallel: params.Parallel,
35 },
36 },
37 }
38 if params.Attributes != nil {
39 cmd.Attributes = *params.Attributes
40 }
41 if params.Label != nil {
42 cmd.Composite.Label = *params.Label
43 }
44 return cmd
45 }
46
47 type ExecCommandParams struct {
48 Id string
49 Attributes *attributes.Attributes
50
51 CommandLine string
52 Component string
53 WorkingDir string
54 Env []v1alpha2.EnvVar
55 HotReloadCapable *bool
56
57 Label *string
58 Kind v1alpha2.CommandGroupKind
59 IsDefault *bool
60 }
61
62 func GetExecCommand(params ExecCommandParams) v1alpha2.Command {
63 cmd := v1alpha2.Command{
64 Id: params.Id,
65 CommandUnion: v1alpha2.CommandUnion{
66 Exec: &v1alpha2.ExecCommand{
67 LabeledCommand: v1alpha2.LabeledCommand{
68 BaseCommand: v1alpha2.BaseCommand{
69 Group: &v1alpha2.CommandGroup{
70 Kind: params.Kind,
71 IsDefault: params.IsDefault,
72 },
73 },
74 },
75 CommandLine: params.CommandLine,
76 Component: params.Component,
77 WorkingDir: params.WorkingDir,
78 Env: params.Env,
79 HotReloadCapable: params.HotReloadCapable,
80 },
81 },
82 }
83 if params.Attributes != nil {
84 cmd.Attributes = *params.Attributes
85 }
86 if params.Label != nil {
87 cmd.Composite.Label = *params.Label
88 }
89 return cmd
90 }
91
92 type ApplyCommandParams struct {
93 Id string
94 Attributes *attributes.Attributes
95
96 Component string
97
98 Label *string
99 Kind v1alpha2.CommandGroupKind
100 IsDefault *bool
101 }
102
103 func GetApplyCommand(params ApplyCommandParams) v1alpha2.Command {
104 cmd := v1alpha2.Command{
105 Id: params.Id,
106 CommandUnion: v1alpha2.CommandUnion{
107 Apply: &v1alpha2.ApplyCommand{
108 LabeledCommand: v1alpha2.LabeledCommand{
109 BaseCommand: v1alpha2.BaseCommand{
110 Group: &v1alpha2.CommandGroup{
111 Kind: params.Kind,
112 IsDefault: params.IsDefault,
113 },
114 },
115 },
116 Component: params.Component,
117 },
118 },
119 }
120 if params.Attributes != nil {
121 cmd.Attributes = *params.Attributes
122 }
123 if params.Label != nil {
124 cmd.Composite.Label = *params.Label
125 }
126 return cmd
127 }
128
View as plain text