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

Function GetProjectNamesFunc

pkg/ddevapp/utils.go:432–469  ·  view source on GitHub ↗

GetProjectNamesFunc returns a function for autocompleting project names for command arguments. If status is "inactive" or "active", only names of inactive or active projects respectively are returned. If status is "all", all project names are returned. If numArgs is 0, completion will be provided fo

(status string, numArgs int)

Source from the content-addressed store, hash-verified

430// If numArgs is 0, completion will be provided for infinite arguments,
431// otherwise it will only be provided for the numArgs number of arguments.
432func GetProjectNamesFunc(status string, numArgs int) func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {
433 return func(_ *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective) {
434 // Don't provide completions if the user keeps hitting space after
435 // exhausting all of the valid arguments.
436 if numArgs > 0 && len(args)+1 > numArgs {
437 return nil, cobra.ShellCompDirectiveNoFileComp
438 }
439
440 // Get all of the projects we're interested in for this completion function.
441 var apps []*DdevApp
442 var err error
443 if status == "inactive" {
444 apps, err = GetInactiveProjects()
445 } else if status == "active" {
446 apps, err = GetProjects(true)
447 } else if status == "all" {
448 apps, err = GetProjects(false)
449 } else {
450 // This is an error state - but we just return nothing
451 return nil, cobra.ShellCompDirectiveNoFileComp
452 }
453 // Return nothing if we have nothing, or return all of the project names.
454 // Note that if there's nothing to return, we don't let cobra pick completions
455 // from the files in the cwd.
456 if err != nil {
457 return nil, cobra.ShellCompDirectiveNoFileComp
458 }
459
460 // Don't show arguments that are already written on the command line
461 var projectNames []string
462 for _, name := range ExtractProjectNames(apps) {
463 if !slices.Contains(args, name) {
464 projectNames = append(projectNames, name)
465 }
466 }
467 return projectNames, cobra.ShellCompDirectiveNoFileComp
468 }
469}
470
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.

Callers 15

logs.goFile · 0.92
stop.goFile · 0.92
start.goFile · 0.92
clean.goFile · 0.92
share.goFile · 0.92
debug-cd.goFile · 0.92
xhgui.goFile · 0.92
restart.goFile · 0.92
mutagen-sync.goFile · 0.92
mutagen-status.goFile · 0.92
delete.goFile · 0.92
initFunction · 0.92

Calls 3

GetInactiveProjectsFunction · 0.85
GetProjectsFunction · 0.85
ExtractProjectNamesFunction · 0.85

Tested by

no test coverage detected