MCPcopy Index your code
hub / github.com/cloudspannerecosystem/spanner-cli / readInteractiveInput

Function readInteractiveInput

cli.go:339–370  ·  view source on GitHub ↗
(rl *readline.Instance, prompt string)

Source from the content-addressed store, hash-verified

337}
338
339func readInteractiveInput(rl *readline.Instance, prompt string) (*inputStatement, error) {
340 defer rl.SetPrompt(prompt)
341
342 var input string
343 for {
344 line, err := rl.Readline()
345 if err != nil {
346 return nil, err
347 }
348 input += line + "\n"
349
350 statements := separateInput(input)
351 switch len(statements) {
352 case 0:
353 // read next input
354 case 1:
355 if statements[0].delim != delimiterUndefined {
356 return &statements[0], nil
357 }
358 // read next input
359 default:
360 return nil, errors.New("sql queries are limited to single statements")
361 }
362
363 // show prompt to urge next input
364 var margin string
365 if l := len(prompt); l >= 3 {
366 margin = strings.Repeat(" ", l-3)
367 }
368 rl.SetPrompt(margin + "-> ")
369 }
370}
371
372func printResult(out io.Writer, result *Result, mode DisplayMode, interactive, verbose bool) {
373 if mode == DisplayModeTable {

Callers 2

RunInteractiveMethod · 0.85
TestReadInteractiveInputFunction · 0.85

Calls 1

separateInputFunction · 0.85

Tested by 1

TestReadInteractiveInputFunction · 0.68