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

This commit is contained in:
ahmed
2023-01-19 12:58:50 -05:00
committed by GitHub
parent 86f80fc5a8
commit 2060ae1c47
+13 -1
View File
@@ -3,10 +3,13 @@ package output
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"sort"
"strings" "strings"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/sirupsen/logrus" "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/detectors"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/source_metadatapb" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/source_metadatapb"
@@ -43,11 +46,20 @@ func PrintPlainOutput(r *detectors.ResultWithMetadata) {
printer.Printf("Detector Type: %s\n", out.DetectorType) printer.Printf("Detector Type: %s\n", out.DetectorType)
printer.Printf("Decoder Type: %s\n", out.DecoderType) printer.Printf("Decoder Type: %s\n", out.DecoderType)
printer.Printf("Raw result: %s\n", whitePrinter.Sprint(out.Raw)) printer.Printf("Raw result: %s\n", whitePrinter.Sprint(out.Raw))
var aggregateData = make(map[string]interface{})
var aggregateDataKeys []string
for _, data := range meta { for _, data := range meta {
for k, v := range data { 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("") fmt.Println("")
} }