MCPcopy
hub / github.com/turbot/steampipe / getQuery

Method getQuery

pkg/interactive/interactive_client.go:414–513  ·  view source on GitHub ↗
(ctx context.Context, line string)

Source from the content-addressed store, hash-verified

412}
413
414func (c *InteractiveClient) getQuery(ctx context.Context, line string) *modconfig.ResolvedQuery {
415 // if it's an empty line, then we don't need to do anything
416 if line == "" {
417 return nil
418 }
419
420 // store the history (the raw line which was entered)
421 historyEntry := line
422 defer func() {
423 if len(historyEntry) > 0 {
424 // we want to store even if we fail to resolve a query
425 c.interactiveQueryHistory.Push(historyEntry)
426 }
427
428 }()
429
430 // wait for initialisation to complete so we can access the workspace
431 if !c.isInitialised() {
432 // create a context used purely to detect cancellation during initialisation
433 // this will also set c.cancelActiveQuery
434 queryCtx := c.createQueryContext(ctx)
435 defer func() {
436 // cancel this context
437 c.cancelActiveQueryIfAny()
438 }()
439
440 // show the spinner here while we wait for initialization to complete
441 statushooks.Show(ctx)
442 // wait for client initialisation to complete
443 err := c.waitForInitData(queryCtx)
444 statushooks.Done(ctx)
445 if err != nil {
446 // clear history entry
447 historyEntry = ""
448 // clear the interactive buffer
449 c.interactiveBuffer = nil
450 // error will have been handled elsewhere
451 return nil
452 }
453 }
454
455 // push the current line into the buffer
456 c.interactiveBuffer = append(c.interactiveBuffer, line)
457
458 // expand the buffer out into 'query'
459 queryString := strings.Join(c.interactiveBuffer, "\n")
460
461 // check if the contents in the buffer evaluates to a metaquery
462 if metaquery.IsMetaQuery(line) {
463 // this is a metaquery
464 // clear the interactive buffer
465 c.interactiveBuffer = nil
466 return &modconfig.ResolvedQuery{
467 ExecuteSQL: line,
468 IsMetaQuery: true,
469 }
470 }
471

Callers 1

executorMethod · 0.95

Calls 12

isInitialisedMethod · 0.95
createQueryContextMethod · 0.95
waitForInitDataMethod · 0.95
shouldExecuteMethod · 0.95
ShowFunction · 0.92
DoneFunction · 0.92
IsMetaQueryFunction · 0.92
ShowErrorFunction · 0.92
PushMethod · 0.80

Tested by

no test coverage detected