| 365 | } |
| 366 | |
| 367 | func confirmDefaultsUpdate( |
| 368 | target defaultsTarget, |
| 369 | inputFile string, |
| 370 | changes []defaultsUpdateChange, |
| 371 | skipConfirmation bool, |
| 372 | confirmAction func(title, affirmative, negative string) (bool, error), |
| 373 | ) error { |
| 374 | renderDefaultsUpdatePreview(target, inputFile, changes) |
| 375 | |
| 376 | if skipConfirmation { |
| 377 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Skipping confirmation because --yes was provided.")) |
| 378 | return nil |
| 379 | } |
| 380 | |
| 381 | confirmed, err := confirmAction( |
| 382 | "Do you want to update these defaults?", |
| 383 | "Yes, update", |
| 384 | "No, cancel", |
| 385 | ) |
| 386 | if err != nil { |
| 387 | return fmt.Errorf("failed to get confirmation: %w", err) |
| 388 | } |
| 389 | if !confirmed { |
| 390 | return errors.New("defaults update cancelled") |
| 391 | } |
| 392 | return nil |
| 393 | } |
| 394 | |
| 395 | func renderDefaultsUpdatePreview(target defaultsTarget, inputFile string, changes []defaultsUpdateChange) { |
| 396 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Defaults update preview:")) |