Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 Allow printing data queries without an assessment #4693

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions cli/printer/mql.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,7 @@ import (
"golang.org/x/exp/slices"
)

// Results prints a full query with all data points
// NOTE: ensure that results only contains results that match the bundle!
func (print *Printer) Results(bundle *llx.CodeBundle, results map[string]*llx.RawResult) string {
assessment := llx.Results2Assessment(bundle, results)

if assessment != nil {
return print.Assessment(bundle, assessment)
}

func (print *Printer) Datas(bundle *llx.CodeBundle, results map[string]*llx.RawResult) string {
var res strings.Builder
i := 0
for _, v := range results {
Expand All @@ -38,6 +30,18 @@ func (print *Printer) Results(bundle *llx.CodeBundle, results map[string]*llx.Ra
return res.String()
}

// Results prints a full query with all data points
// NOTE: ensure that results only contains results that match the bundle!
func (print *Printer) Results(bundle *llx.CodeBundle, results map[string]*llx.RawResult) string {
assessment := llx.Results2Assessment(bundle, results)

if assessment != nil {
return print.Assessment(bundle, assessment)
}

return print.Datas(bundle, results)
Copy link
Contributor

@preslavgerchev preslavgerchev Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to double check: is this PR just a restructure/cleanup or are there functional changes?

from what I see the only thing that happens here is that we've moved the for loop into its own Datas func that still gets called if assessment is nil

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, i see the use case in mondoohq/cnspec#1438 for extracting that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just splits the function into 2 so that it can be used from cnspec

}

// Assessment prints a complete comparable assessment
func (print *Printer) Assessment(bundle *llx.CodeBundle, assessment *llx.Assessment) string {
var res strings.Builder
Expand Down
Loading