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

Updated stdout to print results in alphabetical order for consistent output #1032

Merged
merged 1 commit into from
Jan 19, 2023
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
14 changes: 13 additions & 1 deletion pkg/output/plain.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package output
import (
"encoding/json"
"fmt"
"sort"
"strings"

"github.com/fatih/color"
"github.com/sirupsen/logrus"
"golang.org/x/text/cases"
"golang.org/x/text/language"

"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/source_metadatapb"
Expand Down Expand Up @@ -43,11 +46,20 @@ func PrintPlainOutput(r *detectors.ResultWithMetadata) {
printer.Printf("Detector Type: %s\n", out.DetectorType)
printer.Printf("Decoder Type: %s\n", out.DecoderType)
printer.Printf("Raw result: %s\n", whitePrinter.Sprint(out.Raw))

var aggregateData = make(map[string]interface{})
var aggregateDataKeys []string

for _, data := range meta {
for k, v := range data {
printer.Printf("%s: %v\n", strings.Title(k), v)
aggregateDataKeys = append(aggregateDataKeys, k)
aggregateData[k] = v
}
}
sort.Strings(aggregateDataKeys)
for _, k := range aggregateDataKeys {
printer.Printf("%s: %v\n", cases.Title(language.AmericanEnglish).String(k), aggregateData[k])
}
fmt.Println("")
}

Expand Down