Files
steampipe/pkg/interactive/metaquery/handler_search_path.go
kaidaguerre b06348757a Fix linting warnings
---------

Co-authored-by: Binaek Sarkar <binaek@turbot.com>
Co-authored-by: Puskar Basu <puskar@turbot.com>
2023-07-06 16:08:23 +01:00

57 lines
1.6 KiB
Go

package metaquery
import (
"context"
"strings"
"github.com/spf13/viper"
"github.com/turbot/go-kit/helpers"
"github.com/turbot/steampipe/pkg/constants"
"github.com/turbot/steampipe/pkg/display"
)
func setOrGetSearchPath(ctx context.Context, input *HandlerInput) error {
if len(input.args()) == 0 {
sessionSearchPath := input.Client.GetRequiredSessionSearchPath()
sessionSearchPath = helpers.RemoveFromStringSlice(sessionSearchPath, constants.InternalSchema)
display.ShowWrappedTable(
[]string{"search_path"},
[][]string{
{strings.Join(sessionSearchPath, ",")},
},
&display.ShowWrappedTableOptions{AutoMerge: false},
)
} else {
arg := input.args()[0]
var paths []string
split := strings.Split(arg, ",")
for _, s := range split {
s = strings.TrimSpace(s)
paths = append(paths, s)
}
viper.Set(constants.ArgSearchPath, paths)
// now that the viper is set, call back into the client (exposed via QueryExecutor) which
// already knows how to setup the search_paths with the viper values
return input.Client.SetRequiredSessionSearchPath(ctx)
}
return nil
}
func setSearchPathPrefix(ctx context.Context, input *HandlerInput) error {
arg := input.args()[0]
paths := []string{}
split := strings.Split(arg, ",")
for _, s := range split {
s = strings.TrimSpace(s)
paths = append(paths, s)
}
viper.Set(constants.ArgSearchPathPrefix, paths)
// now that the viper is set, call back into the client (exposed via QueryExecutor) which
// already knows how to setup the search_paths with the viper values
return input.Client.SetRequiredSessionSearchPath(ctx)
}