Skip to content

Commit

Permalink
Port to v9 schema
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Zunker <[email protected]>
  • Loading branch information
czunker committed Sep 25, 2023
1 parent 35b1958 commit 9d56633
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 169 deletions.
8 changes: 3 additions & 5 deletions cli/printer/mql.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"time"

"go.mondoo.com/cnquery/llx"
"go.mondoo.com/cnquery/resources/packs/all/info"
"go.mondoo.com/cnquery/types"
"go.mondoo.com/cnquery/utils/sortx"
"golang.org/x/exp/slices"
Expand Down Expand Up @@ -321,8 +320,6 @@ func (print *Printer) refMap(typ types.Type, data map[string]interface{}, codeID
}
}

schema := info.Registry.Schema()

code := bundle.CodeV2
ep := code.Blocks[0].Entrypoints[0]
chunk := code.Chunk(ep)
Expand All @@ -336,8 +333,9 @@ func (print *Printer) refMap(typ types.Type, data map[string]interface{}, codeID

nonDefaultFields := []string{}
defaultFields := []string{}
if listType != "" {
if resourceInfo, ok := schema.GetResources()[listType]; ok {
if listType != "" && print.schema != nil {
resourceInfo := (*print.schema).Lookup(listType)
if resourceInfo != nil {
defaultFields = strings.Split(resourceInfo.Defaults, " ")
}
}
Expand Down
6 changes: 6 additions & 0 deletions cli/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/muesli/termenv"
"go.mondoo.com/cnquery/cli/theme/colors"
"go.mondoo.com/cnquery/llx"
)

// Printer turns code into human-readable strings
Expand All @@ -22,6 +23,7 @@ type Printer struct {
Disabled func(...interface{}) string
Failed func(...interface{}) string
Success func(...interface{}) string
schema *llx.Schema
}

// DefaultPrinter that can be used without additional configuration
Expand Down Expand Up @@ -52,6 +54,10 @@ var DefaultPrinter = Printer{
},
}

func (p *Printer) SetSchema(schema *llx.Schema) {
p.schema = schema
}

// PlainNoColorPrinter is a printer without colors
var PlainNoColorPrinter = Printer{
Primary: fmt.Sprint,
Expand Down
Loading

0 comments on commit 9d56633

Please sign in to comment.