MCPcopy
hub / github.com/pocketbase/pocketbase / YesNoPrompt

Function YesNoPrompt

tools/osutils/cmd.go:40–65  ·  view source on GitHub ↗

YesNoPrompt performs a console prompt that asks the user for Yes/No answer. If the user just press Enter (aka. doesn't type anything) it returns the fallback value.

(message string, fallback bool)

Source from the content-addressed store, hash-verified

38//
39// If the user just press Enter (aka. doesn't type anything) it returns the fallback value.
40func YesNoPrompt(message string, fallback bool) bool {
41 options := "Y/n"
42 if !fallback {
43 options = "y/N"
44 }
45
46 r := bufio.NewReader(os.Stdin)
47
48 var s string
49 for {
50 fmt.Fprintf(os.Stderr, "%s (%s) ", message, options)
51
52 s, _ = r.ReadString('\n')
53
54 s = strings.ToLower(strings.TrimSpace(s))
55
56 switch s {
57 case "":
58 return fallback
59 case "y", "yes":
60 return true
61 case "n", "no":
62 return false
63 }
64 }
65}

Callers 4

TestYesNoPromptFunction · 0.92
RunMethod · 0.92
updateCmdMethod · 0.92
migrateCreateHandlerMethod · 0.92

Calls 1

NewReaderMethod · 0.80

Tested by 1

TestYesNoPromptFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…