github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/steampipeconfig/options/general.go (about)

     1  package options
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/turbot/steampipe/pkg/constants"
     8  )
     9  
    10  type General struct {
    11  	UpdateCheck *string `hcl:"update_check"`
    12  	Telemetry   *string `hcl:"telemetry"`
    13  	LogLevel    *string `hcl:"log_level"`
    14  	MemoryMaxMb *int    `hcl:"memory_max_mb"`
    15  }
    16  
    17  // ConfigMap creates a config map that can be merged with viper
    18  func (g *General) ConfigMap() map[string]interface{} {
    19  	// only add keys which are non null
    20  	res := map[string]interface{}{}
    21  	if g.UpdateCheck != nil {
    22  		res[constants.ArgUpdateCheck] = g.UpdateCheck
    23  	}
    24  	if g.Telemetry != nil {
    25  		res[constants.ArgTelemetry] = g.Telemetry
    26  	}
    27  	if g.LogLevel != nil {
    28  		res[constants.ArgLogLevel] = g.LogLevel
    29  	}
    30  	if g.MemoryMaxMb != nil {
    31  		res[constants.ArgMemoryMaxMb] = g.MemoryMaxMb
    32  	}
    33  
    34  	return res
    35  }
    36  
    37  // Merge merges other options over the top of this options object
    38  // i.e. if a property is set in otherOptions, it takes precedence
    39  func (g *General) Merge(otherOptions Options) {
    40  	switch o := otherOptions.(type) {
    41  	case *General:
    42  		if o.UpdateCheck != nil {
    43  			g.UpdateCheck = o.UpdateCheck
    44  		}
    45  	}
    46  }
    47  
    48  func (g *General) String() string {
    49  	if g == nil {
    50  		return ""
    51  	}
    52  	var str []string
    53  	if g.UpdateCheck == nil {
    54  		str = append(str, "  UpdateCheck: nil")
    55  	} else {
    56  		str = append(str, fmt.Sprintf("  UpdateCheck: %s", *g.UpdateCheck))
    57  	}
    58  	if g.Telemetry == nil {
    59  		str = append(str, "  Telemetry: nil")
    60  	} else {
    61  		str = append(str, fmt.Sprintf("  Telemetry: %s", *g.Telemetry))
    62  	}
    63  	if g.LogLevel == nil {
    64  		str = append(str, "  LogLevel: nil")
    65  	} else {
    66  		str = append(str, fmt.Sprintf("  LogLevel: %s", *g.LogLevel))
    67  	}
    68  
    69  	if g.MemoryMaxMb == nil {
    70  		str = append(str, "  MemoryMaxMb: nil")
    71  	} else {
    72  		str = append(str, fmt.Sprintf("  MemoryMaxMb: %d", *g.MemoryMaxMb))
    73  	}
    74  	return strings.Join(str, "\n")
    75  }