MCPcopy Create free account
hub / github.com/OverloadBlitz/cloudcent-cli / readBaselineMonthlyTotal

Function readBaselineMonthlyTotal

cmd/pulumi.go:412–433  ·  view source on GitHub ↗

readBaselineMonthlyTotal extracts totals.monthly_total from a previously saved estimate JSON document (the output of `pulumi estimate -o json`).

(path string)

Source from the content-addressed store, hash-verified

410// readBaselineMonthlyTotal extracts totals.monthly_total from a previously saved
411// estimate JSON document (the output of `pulumi estimate -o json`).
412func readBaselineMonthlyTotal(path string) (float64, error) {
413 data, err := os.ReadFile(path)
414 if err != nil {
415 return 0, err
416 }
417 var doc struct {
418 Totals struct {
419 MonthlyTotal string `json:"monthly_total"`
420 } `json:"totals"`
421 }
422 if err := json.Unmarshal(data, &doc); err != nil {
423 return 0, fmt.Errorf("parsing baseline JSON: %w", err)
424 }
425 if strings.TrimSpace(doc.Totals.MonthlyTotal) == "" {
426 return 0, fmt.Errorf("baseline JSON has no totals.monthly_total")
427 }
428 v, err := strconv.ParseFloat(doc.Totals.MonthlyTotal, 64)
429 if err != nil {
430 return 0, fmt.Errorf("baseline monthly_total %q is not a number: %w", doc.Totals.MonthlyTotal, err)
431 }
432 return v, nil
433}
434
435// printGuardrailVerdict writes a coloured pass/fail summary to stderr, keeping
436// stdout reserved for the estimate tables.

Callers 1

buildGuardrailConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected