in internal/pkg/term/selector/selector.go [532:578]
func (s *CFTaskSelector) Task(msg, help string, opts ...GetDeployedTaskOpts) (string, error) {
for _, opt := range opts {
opt(s)
}
if s.defaultCluster && (s.env != "" || s.app != "") {
// Error for callers
return "", fmt.Errorf("cannot specify both default cluster and env")
}
if !s.defaultCluster && (s.env == "" && s.app == "") {
return "", fmt.Errorf("must specify either app and env or default cluster")
}
var tasks []deploy.TaskStackInfo
var err error
if s.defaultCluster {
defaultTasks, err := s.cfStore.ListDefaultTaskStacks()
if err != nil {
return "", fmt.Errorf("get tasks in default cluster: %w", err)
}
tasks = append(tasks, defaultTasks...)
}
if s.env != "" && s.app != "" {
envTasks, err := s.cfStore.ListTaskStacks(s.app, s.env)
if err != nil {
return "", fmt.Errorf("get tasks in environment %s: %w", s.env, err)
}
tasks = append(tasks, envTasks...)
}
choices := make([]string, len(tasks))
for n, task := range tasks {
choices[n] = task.TaskName()
}
if len(choices) == 0 {
return "", fmt.Errorf("no deployed tasks found in selected cluster")
}
// Return if there's only one option.
if len(choices) == 1 {
log.Infof("Found only one deployed task: %s\n", color.HighlightUserInput(choices[0]))
return choices[0], nil
}
choice, err := s.prompt.SelectOne(msg, help, choices, prompt.WithFinalMessage(taskFinalMsg))
if err != nil {
return "", fmt.Errorf("select task for deletion: %w", err)
}
return choice, nil
}