MCPcopy Create free account
hub / github.com/ddev/ddev / NewTask

Function NewTask

pkg/ddevapp/task.go:120–187  ·  view source on GitHub ↗

NewTask is the factory method to create whatever kind of task we need using the yaml description of the task. Returns a task (of various types) or nil

(app *DdevApp, ytask YAMLTask)

Source from the content-addressed store, hash-verified

118// we need using the yaml description of the task.
119// Returns a task (of various types) or nil
120func NewTask(app *DdevApp, ytask YAMLTask) Task {
121 if value, ok := ytask["exec-host"]; ok {
122 if v, ok := value.(string); ok {
123 t := ExecHostTask{app: app, exec: v}
124 return t
125 }
126 util.Warning("Invalid exec-host value, not executing it: %v", value)
127 } else if value, ok = ytask["composer"]; ok {
128 // Handle the old-style `composer: install`
129 if v, ok := value.(string); ok {
130 t := ComposerTask{app: app, execRaw: strings.Split(v, " ")}
131 return t
132 }
133
134 // Handle the new-style `composer: [install]`
135 if v, ok := ytask["exec_raw"]; ok {
136 raw, err := util.InterfaceSliceToStringSlice(v)
137 if err != nil {
138 util.Warning("Invalid composer/exec_raw value, not executing it: %v", err)
139 return nil
140 }
141
142 t := ComposerTask{app: app, execRaw: raw}
143 return t
144 }
145 util.Warning("Invalid Composer value, not executing it: %v", value)
146 } else if value, ok = ytask["exec"]; ok {
147 if v, ok := value.(string); ok {
148 t := ExecTask{app: app, exec: v}
149 if t.service, ok = ytask["service"].(string); !ok {
150 t.service = nodeps.WebContainer
151 }
152 // Handle user as either string or integer
153 if userVal, ok := ytask["user"].(string); ok {
154 t.user = userVal
155 } else if userVal, ok := ytask["user"].(int); ok {
156 t.user = fmt.Sprintf("%d", userVal)
157 } else {
158 t.user = ""
159 }
160 return t
161 }
162
163 if v, ok := ytask["exec_raw"]; ok {
164 raw, err := util.InterfaceSliceToStringSlice(v)
165 if err != nil {
166 util.Warning("Invalid exec/exec_raw value, not executing it: %v", err)
167 return nil
168 }
169
170 t := ExecTask{app: app, execRaw: raw}
171 if t.service, ok = ytask["service"].(string); !ok {
172 t.service = nodeps.WebContainer
173 }
174 // Handle user as either string or integer
175 if userVal, ok := ytask["user"].(string); ok {
176 t.user = userVal
177 } else if userVal, ok := ytask["user"].(int); ok {

Callers 1

ProcessHooksMethod · 0.85

Calls 2

WarningFunction · 0.92

Tested by

no test coverage detected