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

     1  package metaquery
     2  
     3  import (
     4  	"context"
     5  	"strings"
     6  
     7  	"github.com/spf13/viper"
     8  	"github.com/turbot/go-kit/helpers"
     9  	"github.com/turbot/steampipe/pkg/constants"
    10  	"github.com/turbot/steampipe/pkg/display"
    11  )
    12  
    13  func setOrGetSearchPath(ctx context.Context, input *HandlerInput) error {
    14  	if len(input.args()) == 0 {
    15  		sessionSearchPath := input.Client.GetRequiredSessionSearchPath()
    16  
    17  		sessionSearchPath = helpers.RemoveFromStringSlice(sessionSearchPath, constants.InternalSchema)
    18  
    19  		display.ShowWrappedTable(
    20  			[]string{"search_path"},
    21  			[][]string{
    22  				{strings.Join(sessionSearchPath, ",")},
    23  			},
    24  			&display.ShowWrappedTableOptions{AutoMerge: false},
    25  		)
    26  	} else {
    27  		arg := input.args()[0]
    28  		var paths []string
    29  		split := strings.Split(arg, ",")
    30  		for _, s := range split {
    31  			s = strings.TrimSpace(s)
    32  			paths = append(paths, s)
    33  		}
    34  		viper.Set(constants.ArgSearchPath, paths)
    35  
    36  		// now that the viper is set, call back into the client (exposed via QueryExecutor) which
    37  		// already knows how to setup the search_paths with the viper values
    38  		return input.Client.SetRequiredSessionSearchPath(ctx)
    39  	}
    40  	return nil
    41  }
    42  
    43  func setSearchPathPrefix(ctx context.Context, input *HandlerInput) error {
    44  	arg := input.args()[0]
    45  	paths := []string{}
    46  	split := strings.Split(arg, ",")
    47  	for _, s := range split {
    48  		s = strings.TrimSpace(s)
    49  		paths = append(paths, s)
    50  	}
    51  	viper.Set(constants.ArgSearchPathPrefix, paths)
    52  
    53  	// now that the viper is set, call back into the client (exposed via QueryExecutor) which
    54  	// already knows how to setup the search_paths with the viper values
    55  	return input.Client.SetRequiredSessionSearchPath(ctx)
    56  }