PrintResults renders per-resource pricing tables and a final cost summary.
(results []resources.EstimateResult)
| 231 | |
| 232 | // PrintResults renders per-resource pricing tables and a final cost summary. |
| 233 | func PrintResults(results []resources.EstimateResult) { |
| 234 | titleSt := lipgloss.NewStyle().Foreground(colTitle).Bold(true) |
| 235 | mutedSt := lipgloss.NewStyle().Foreground(colMuted) |
| 236 | warnSt := lipgloss.NewStyle().Foreground(lipgloss.Color("#F59E0B")) |
| 237 | subLabelSt := lipgloss.NewStyle().Foreground(colHeader).Bold(true) |
| 238 | |
| 239 | var regionFallbackNames []string |
| 240 | regionFallbackProviders := map[string]bool{} |
| 241 | |
| 242 | groups := groupResults(results) |
| 243 | |
| 244 | for i, g := range groups { |
| 245 | first := g.results[0] |
| 246 | fmt.Println() |
| 247 | fmt.Printf("%s %s\n", |
| 248 | titleSt.Render(fmt.Sprintf("[%d] %s", i+1, first.ResourceName)), |
| 249 | mutedSt.Render("("+first.Product+")"), |
| 250 | ) |
| 251 | |
| 252 | if len(first.Props) > 0 { |
| 253 | propKeys := make([]string, 0, len(first.Props)) |
| 254 | for k := range first.Props { |
| 255 | propKeys = append(propKeys, k) |
| 256 | } |
| 257 | sort.Strings(propKeys) |
| 258 | for _, k := range propKeys { |
| 259 | fmt.Printf(" %s %s\n", |
| 260 | mutedSt.Render(fmt.Sprintf("%-18s", k)), |
| 261 | first.Props[k], |
| 262 | ) |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | if first.InputsJSON != "" { |
| 267 | fmt.Printf(" %s\n", mutedSt.Render("Input properties:")) |
| 268 | fmt.Println(indent(first.InputsJSON, " ")) |
| 269 | } |
| 270 | |
| 271 | if first.RegionFallback { |
| 272 | regionFallbackNames = append(regionFallbackNames, first.ResourceName) |
| 273 | // Infer provider from resource type string. |
| 274 | rawType := first.Props["type"] |
| 275 | switch { |
| 276 | case strings.HasPrefix(rawType, "azure-native:") || strings.HasPrefix(rawType, "azure:"): |
| 277 | regionFallbackProviders["azure"] = true |
| 278 | case strings.HasPrefix(rawType, "gcp:"): |
| 279 | regionFallbackProviders["gcp"] = true |
| 280 | case strings.HasPrefix(rawType, "oci:"): |
| 281 | regionFallbackProviders["oci"] = true |
| 282 | default: |
| 283 | regionFallbackProviders["aws"] = true |
| 284 | } |
| 285 | fmt.Printf(" %s\n", warnSt.Render(fmt.Sprintf("⚠ Region not detected — using %q as fallback", first.Region))) |
| 286 | } |
| 287 | |
| 288 | for _, r := range g.results { |
| 289 | if r.SubLabel != "" { |
| 290 | fmt.Printf("\n %s\n", subLabelSt.Render("── "+r.SubLabel+" ──")) |
no test coverage detected