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

Method GetXDdevExtension

pkg/ddevapp/compose_yaml.go:146–178  ·  view source on GitHub ↗

GetXDdevExtension retrieves the x-ddev extension for a given service from the ComposeYaml

(serviceName string)

Source from the content-addressed store, hash-verified

144
145// GetXDdevExtension retrieves the x-ddev extension for a given service from the ComposeYaml
146func (app *DdevApp) GetXDdevExtension(serviceName string) XDdevExtension {
147 var xDdev XDdevExtension
148 // Set defaults for web and db services
149 if serviceName == "web" || serviceName == "db" {
150 xDdev.SSHShell = "bash"
151 }
152 // And check for user overrides
153 if app.ComposeYaml != nil && app.ComposeYaml.Services != nil {
154 if composeService, ok := app.ComposeYaml.Services[serviceName]; ok {
155 if found, err := composeService.Extensions.Get("x-ddev", &xDdev); err == nil && found {
156 // Trim whitespace from all string fields
157 xDdev.DescribeInfo = strings.TrimSpace(xDdev.DescribeInfo)
158 xDdev.DescribeURLPort = strings.TrimSpace(xDdev.DescribeURLPort)
159 xDdev.SSHShell = strings.TrimSpace(xDdev.SSHShell)
160 }
161 }
162 }
163 // Default to sh if no shell specified
164 if xDdev.SSHShell == "" {
165 xDdev.SSHShell = "sh"
166 }
167 // Append shell info to DescribeInfo if it's not the default
168 hasCustomShell := false
169 if serviceName == "web" || serviceName == "db" {
170 hasCustomShell = xDdev.SSHShell != "bash"
171 } else {
172 hasCustomShell = xDdev.SSHShell != "sh"
173 }
174 if hasCustomShell {
175 xDdev.DescribeInfo = strings.TrimSpace(fmt.Sprintf("%s\nShell: %s", xDdev.DescribeInfo, xDdev.SSHShell))
176 }
177 return xDdev
178}
179
180// GetDdevLabels returns labels for DDEV resources. If app is nil, only global
181// labels are returned. If app is provided, project-specific labels are added.

Callers 3

TestGetXDdevExtensionFunction · 0.95
DescribeMethod · 0.95
ssh.goFile · 0.80

Calls 1

GetMethod · 0.65

Tested by 1

TestGetXDdevExtensionFunction · 0.76