MCPcopy Create free account
hub / github.com/github/gh-aw / confirmDefaultsUpdate

Function confirmDefaultsUpdate

pkg/cli/env_command.go:367–393  ·  view source on GitHub ↗
(
	target defaultsTarget,
	inputFile string,
	changes []defaultsUpdateChange,
	skipConfirmation bool,
	confirmAction func(title, affirmative, negative string) (bool, error),
)

Source from the content-addressed store, hash-verified

365}
366
367func 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
395func renderDefaultsUpdatePreview(target defaultsTarget, inputFile string, changes []defaultsUpdateChange) {
396 fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Defaults update preview:"))

Callers 2

defaultsUpdateFromFileFunction · 0.85

Calls 3

FormatInfoMessageFunction · 0.92
ErrorfMethod · 0.45

Tested by 1