buildGuardrailConfig assembles a GuardrailConfig from the parsed flags, loading the baseline estimate JSON when --baseline is given.
(cmd *cobra.Command)
| 381 | // buildGuardrailConfig assembles a GuardrailConfig from the parsed flags, |
| 382 | // loading the baseline estimate JSON when --baseline is given. |
| 383 | func buildGuardrailConfig(cmd *cobra.Command) (estimate.GuardrailConfig, error) { |
| 384 | var cfg estimate.GuardrailConfig |
| 385 | |
| 386 | if cmd.Flags().Changed("budget") { |
| 387 | v := pulumiEstimateBudget |
| 388 | cfg.Budget = &v |
| 389 | } |
| 390 | if cmd.Flags().Changed("max-increase") { |
| 391 | v := pulumiEstimateMaxIncrease |
| 392 | cfg.MaxIncrease = &v |
| 393 | } |
| 394 | if cmd.Flags().Changed("max-increase-pct") { |
| 395 | v := pulumiEstimateMaxIncreasePct |
| 396 | cfg.MaxIncreasePct = &v |
| 397 | } |
| 398 | |
| 399 | if strings.TrimSpace(pulumiEstimateBaseline) != "" { |
| 400 | baseline, err := readBaselineMonthlyTotal(pulumiEstimateBaseline) |
| 401 | if err != nil { |
| 402 | return cfg, fmt.Errorf("reading --baseline: %w", err) |
| 403 | } |
| 404 | cfg.Baseline = &baseline |
| 405 | } |
| 406 | |
| 407 | return cfg, nil |
| 408 | } |
| 409 | |
| 410 | // readBaselineMonthlyTotal extracts totals.monthly_total from a previously saved |
| 411 | // estimate JSON document (the output of `pulumi estimate -o json`). |
no test coverage detected