MCPcopy Index your code
hub / github.com/nikivdev/go / promptWithDefault

Function promptWithDefault

main.go:1205–1223  ·  view source on GitHub ↗
(out io.Writer, reader *bufio.Reader, label, defaultValue string)

Source from the content-addressed store, hash-verified

1203}
1204
1205func promptWithDefault(out io.Writer, reader *bufio.Reader, label, defaultValue string) (string, error) {
1206 label = strings.TrimSpace(label)
1207 prompt := label
1208 if defaultValue != "" {
1209 prompt += fmt.Sprintf(" [%s]", defaultValue)
1210 }
1211 prompt += ": "
1212 fmt.Fprint(out, prompt)
1213
1214 line, err := reader.ReadString('\n')
1215 if err != nil && !errors.Is(err, io.EOF) {
1216 return "", fmt.Errorf("read input: %w", err)
1217 }
1218 line = strings.TrimRight(line, "\r\n")
1219 if strings.TrimSpace(line) == "" {
1220 return defaultValue, nil
1221 }
1222 return line, nil
1223}
1224
1225func promptYesNo(out io.Writer, in io.Reader, label string, defaultYes bool) (bool, error) {
1226 reader := bufio.NewReader(in)

Callers 4

workspaceAddPathFunction · 0.70
promptPullRequestDetailsFunction · 0.70
promptRepoFunction · 0.70
promptPullRequestNumberFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected