github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/interactive/run.go (about)

     1  package interactive
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/turbot/steampipe/pkg/constants"
     7  	"github.com/turbot/steampipe/pkg/db/db_local"
     8  	"github.com/turbot/steampipe/pkg/error_helpers"
     9  	"github.com/turbot/steampipe/pkg/query"
    10  	"github.com/turbot/steampipe/pkg/query/queryresult"
    11  )
    12  
    13  type RunInteractivePromptResult struct {
    14  	Streamer  *queryresult.ResultStreamer
    15  	PromptErr error
    16  }
    17  
    18  // RunInteractivePrompt starts the interactive query prompt
    19  func RunInteractivePrompt(ctx context.Context, initData *query.InitData) *RunInteractivePromptResult {
    20  	res := &RunInteractivePromptResult{
    21  		Streamer: queryresult.NewResultStreamer(),
    22  	}
    23  
    24  	interactiveClient, err := newInteractiveClient(ctx, initData, res)
    25  	if err != nil {
    26  		error_helpers.ShowErrorWithMessage(ctx, err, "interactive client failed to initialize")
    27  		// do not bind shutdown to any cancellable context
    28  		db_local.ShutdownService(ctx, constants.InvokerQuery)
    29  		res.PromptErr = err
    30  		return res
    31  	}
    32  
    33  	// start the interactive prompt in a go routine
    34  	go interactiveClient.InteractivePrompt(ctx)
    35  
    36  	return res
    37  }