Skip to content

Commit

Permalink
Only show wait spinner in interactive mode . Closes #106
Browse files Browse the repository at this point in the history
  • Loading branch information
binaek authored Jan 29, 2021
1 parent 9cb59e8 commit 93cb973
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions db/client_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,26 @@ import (
"golang.org/x/text/language"
"golang.org/x/text/message"

"github.com/turbot/steampipe/cmdconfig"
"github.com/turbot/steampipe/constants"
"github.com/turbot/steampipe/utils"
)

// ExecuteSync :: execute a query against this client and wait for the result
func (c *Client) ExecuteSync(query string) (*SyncQueryResult, error) {
start := time.Now()
// https://github.com/golang/go/wiki/CodeReviewComments#indent-error-flow
result, err := c.executeQuery(query)
result, err := c.executeQuery(query, false)
if err != nil {
return nil, err
}
syncResult := &SyncQueryResult{ColTypes: result.ColTypes}
for row := range *result.RowChan {
syncResult.Rows = append(syncResult.Rows, row)
}
syncResult.Duration = time.Since(start)
syncResult.Duration = <-result.Duration
return syncResult, nil
}

func (c *Client) executeQuery(query string) (*QueryResult, error) {
func (c *Client) executeQuery(query string, showSpinner bool) (*QueryResult, error) {
if query == "" {
return &QueryResult{}, nil
}
Expand All @@ -42,7 +40,9 @@ func (c *Client) executeQuery(query string) (*QueryResult, error) {
// start spinner after a short delay
var spinner *spinner.Spinner

if cmdconfig.Viper().Get(constants.ArgOutput) == constants.ArgTable {
if showSpinner {
// if showspinner is false, the spinner gets created, but is never shown
// so the s.Active() will always come back false . . .
spinner = utils.StartSpinnerAfterDelay("Loading results...", constants.SpinnerShowTimeout, queryDone)
}

Expand Down
2 changes: 1 addition & 1 deletion db/interactive_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (c *InteractiveClient) executor(line string, resultsStreamer *ResultStreame
resultsStreamer.Done()
} else {
// otherwise execute query
if result, err := c.client.executeQuery(query); err != nil {
if result, err := c.client.executeQuery(query, true); err != nil {
utils.ShowError(err)
resultsStreamer.Done()
} else {
Expand Down
2 changes: 1 addition & 1 deletion db/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func ExecuteQuery(queryString string) (*ResultStreamer, error) {
// start the interactive prompt in a go routine
go interactiveClient.InteractiveQuery(resultsStreamer, onComplete)
} else {
result, err := client.executeQuery(queryString)
result, err := client.executeQuery(queryString, false)
if err != nil {
onComplete()
return nil, err
Expand Down

0 comments on commit 93cb973

Please sign in to comment.