github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/display/variables.go (about) 1 package display 2 3 import ( 4 "encoding/json" 5 "fmt" 6 7 "github.com/turbot/steampipe/pkg/error_helpers" 8 "github.com/turbot/steampipe/pkg/steampipeconfig/modconfig" 9 ) 10 11 type variableInfo struct { 12 Name string `json:"name"` 13 Type string `json:"type"` 14 Description string `json:"description"` 15 Default any `json:"value_default"` 16 Value any `json:"value"` 17 ModName string `json:"mod_name"` 18 } 19 20 func ShowVarsListJson(vars []*modconfig.Variable) { 21 var jsonStructs []variableInfo 22 for _, v := range vars { 23 jv := variableInfo{ 24 Name: v.ShortName, 25 Type: v.TypeString, 26 Description: v.GetDescription(), 27 Default: v.DefaultGo, 28 Value: v.ValueGo, 29 ModName: v.ModName, 30 } 31 jsonStructs = append(jsonStructs, jv) 32 } 33 jsonOutput, err := json.MarshalIndent(jsonStructs, "", " ") 34 error_helpers.FailOnErrorWithMessage(err, "failed to marshal variables to JSON") 35 36 fmt.Println(string(jsonOutput)) 37 } 38 39 func ShowVarsListTable(vars []*modconfig.Variable) { 40 headers := []string{"mod_name", "name", "description", "value", "value_default", "type"} 41 var rows = make([][]string, len(vars)) 42 for i, v := range vars { 43 rows[i] = []string{v.ModName, v.ShortName, v.GetDescription(), fmt.Sprintf("%v", v.ValueGo), fmt.Sprintf("%v", v.DefaultGo), v.TypeString} 44 } 45 ShowWrappedTable(headers, rows, &ShowWrappedTableOptions{AutoMerge: false}) 46 }