MCPcopy Index your code
hub / github.com/ddev/ddev / GetServiceNamesFunc

Function GetServiceNamesFunc

pkg/ddevapp/utils.go:473–500  ·  view source on GitHub ↗

GetServiceNamesFunc returns a function for autocompleting service names for service flag. If existingOnly is true, only names of existing services will be returned.

(existingOnly bool)

Source from the content-addressed store, hash-verified

471// GetServiceNamesFunc returns a function for autocompleting service names for service flag.
472// If existingOnly is true, only names of existing services will be returned.
473func GetServiceNamesFunc(existingOnly bool) func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {
474 return func(_ *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective) {
475 // the project name can be passed as an argument
476 projectName := ""
477 if len(args) > 0 {
478 projectName = args[0]
479 }
480 app, err := GetActiveApp(projectName)
481 if err != nil {
482 return nil, cobra.ShellCompDirectiveNoFileComp
483 }
484 if app.ComposeYaml == nil || app.ComposeYaml.Services == nil {
485 return nil, cobra.ShellCompDirectiveNoFileComp
486 }
487 var services []string
488 for service := range app.ComposeYaml.Services {
489 if existingOnly {
490 c, err := app.FindContainerByType(service)
491 if err == nil && c != nil {
492 services = append(services, service)
493 }
494 } else {
495 services = append(services, service)
496 }
497 }
498 return services, cobra.ShellCompDirectiveNoFileComp
499 }
500}
501
502// GetRelativeDirectory returns the directory relative to project root
503// Note that the relative dir is returned as unix-style forward-slashes

Callers 4

initFunction · 0.92
initFunction · 0.92
initFunction · 0.92
initFunction · 0.92

Calls 2

GetActiveAppFunction · 0.85
FindContainerByTypeMethod · 0.80

Tested by

no test coverage detected