package cmd import ( "fmt" "strings" ) // resolveProject takes a project ID or name and returns the project ID. // If the input matches a project ID exactly, it's returned directly. // If it matches project name(s), it returns the ID if exactly one matches. func resolveProject(idOrName string) (string, error) { // First try as an ID project, err := getClient().GetProject(getContext(), idOrName) if err == nil { return project.ID, nil } // Fall back to name lookup projects, err := getClient().ListProjects(getContext()) if err != nil { return "", fmt.Errorf("failed to list projects: %w", err) } var matches []struct{ id, name string } for _, p := range projects { if strings.EqualFold(p.Name, idOrName) { matches = append(matches, struct{ id, name string }{p.ID, p.Name}) } } switch len(matches) { case 0: return "", fmt.Errorf("project %q not found", idOrName) case 1: return matches[0].id, nil default: var names []string for _, m := range matches { names = append(names, fmt.Sprintf("%s (%s)", m.name, m.id)) } return "", fmt.Errorf("ambiguous project name %q matches multiple projects: %s", idOrName, strings.Join(names, ", ")) } }