Rationalising 'status hooks'. Do not show spinner when setting status, instead require an explicit Show. #2432

This commit is contained in:
Binaek Sarkar
2023-03-14 17:18:14 +05:30
committed by GitHub
parent ec35487fd9
commit ee8b6647c4
18 changed files with 155 additions and 148 deletions

View File

@@ -4,21 +4,16 @@ import (
"context"
"errors"
"fmt"
"github.com/spf13/viper"
"github.com/turbot/steampipe/pkg/constants"
"os"
"strings"
"github.com/fatih/color"
"github.com/shiena/ansicolor"
"github.com/spf13/viper"
"github.com/turbot/steampipe/pkg/constants"
"github.com/turbot/steampipe/pkg/statushooks"
)
var (
colorErr = color.RedString("Error")
colorWarn = color.YellowString("Warning")
)
func init() {
color.Output = ansicolor.NewAnsiColorWriter(os.Stderr)
}
@@ -50,7 +45,7 @@ func ShowError(ctx context.Context, err error) {
}
err = HandleCancelError(err)
statushooks.Done(ctx)
fmt.Fprintf(color.Output, "%s: %v\n", colorErr, TransformErrorToSteampipe(err))
fmt.Fprintf(color.Output, "%s: %v\n", constants.ColoredErr, TransformErrorToSteampipe(err))
}
// ShowErrorWithMessage displays the given error nicely with the given message
@@ -60,7 +55,7 @@ func ShowErrorWithMessage(ctx context.Context, err error, message string) {
}
err = HandleCancelError(err)
statushooks.Done(ctx)
fmt.Fprintf(color.Output, "%s: %s - %v\n", colorErr, message, TransformErrorToSteampipe(err))
fmt.Fprintf(color.Output, "%s: %s - %v\n", constants.ColoredErr, message, TransformErrorToSteampipe(err))
}
// TransformErrorToSteampipe removes the pq: and rpc error prefixes along
@@ -113,7 +108,7 @@ func ShowWarning(warning string) {
if len(warning) == 0 {
return
}
fmt.Fprintf(color.Output, "%s: %v\n", colorWarn, warning)
fmt.Fprintf(color.Output, "%s: %v\n", constants.ColoredWarn, warning)
}
func CombineErrorsWithPrefix(prefix string, errors ...error) error {