| 513 | } |
| 514 | |
| 515 | func (c *InteractiveClient) executeMetaquery(ctx context.Context, query string) error { |
| 516 | // the client must be initialised to get here |
| 517 | if !c.isInitialised() { |
| 518 | return fmt.Errorf("client is not initialised") |
| 519 | } |
| 520 | // validate the metaquery arguments |
| 521 | validateResult := metaquery.Validate(query) |
| 522 | if validateResult.Message != "" { |
| 523 | fmt.Println(validateResult.Message) |
| 524 | } |
| 525 | if err := validateResult.Err; err != nil { |
| 526 | return err |
| 527 | } |
| 528 | if !validateResult.ShouldRun { |
| 529 | return nil |
| 530 | } |
| 531 | client := c.client() |
| 532 | |
| 533 | // validation passed, now we will run |
| 534 | return metaquery.Handle(ctx, &metaquery.HandlerInput{ |
| 535 | Query: query, |
| 536 | Client: client, |
| 537 | Schema: c.schemaMetadata, |
| 538 | SearchPath: client.GetRequiredSessionSearchPath(), |
| 539 | Prompt: c.interactivePrompt, |
| 540 | ClosePrompt: func() { c.afterClose = AfterPromptCloseExit }, |
| 541 | GetConnectionStateMap: c.getConnectionState, |
| 542 | }) |
| 543 | } |
| 544 | |
| 545 | // helper function to acquire db connection and retrieve connection state |
| 546 | func (c *InteractiveClient) getConnectionState(ctx context.Context) (steampipeconfig.ConnectionStateMap, error) { |