enhance probe output

This commit is contained in:
M09Ic committed 2024-10-14 02:20:39 +08:00
1 parent d8ed250ae8
commit dc667c9683
3 files changed
+19 -7

No files matched your search

+8 -5
View File
@@ -39,17 +39,20 @@ func Format(opts Option) {
group[result.Url.Host] = append(group[result.Url.Host], &result)
}
// 分组
for _, results := range group {
for _, result := range results {
if !opts.Fuzzy && result.IsFuzzy {
continue
}
if !opts.NoColor {
logs.Log.Console(result.ColorString() + "\n")
if opts.OutputProbe == "" {
if !opts.NoColor {
logs.Log.Console(result.ColorString() + "\n")
} else {
logs.Log.Console(result.String() + "\n")
}
} else {
logs.Log.Console(result.String() + "\n")
probes := strings.Split(opts.OutputProbe, ",")
logs.Log.Console(result.ProbeOutput(probes) + "\n")
}
}
}
+2 -2
View File
@@ -364,7 +364,7 @@ func (r *Runner) Output(bl *pkg.Baseline) {
if r.Option.Json {
out = bl.ToJson()
} else if len(r.Probes) > 0 {
out = bl.Format(r.Probes)
out = bl.ProbeOutput(r.Probes)
} else if r.Color {
out = bl.ColorString()
} else {
@@ -385,7 +385,7 @@ func (r *Runner) Output(bl *pkg.Baseline) {
} else if r.FileOutput == "full" {
r.OutputFile.SafeWrite(bl.String() + "\n")
} else {
r.OutputFile.SafeWrite(bl.Format(strings.Split(r.FileOutput, ",")) + "\n")
r.OutputFile.SafeWrite(bl.ProbeOutput(strings.Split(r.FileOutput, ",")) + "\n")
}
r.OutputFile.SafeSync()
+9
View File
@@ -235,6 +235,15 @@ func (bl *Baseline) Compare(other *Baseline) int {
return -1
}
func (bl *Baseline) ProbeOutput(format []string) string {
var s strings.Builder
for _, f := range format {
s.WriteString("\t")
s.WriteString(bl.Get(f))
}
return strings.TrimSpace(s.String())
}
var Distance uint8 = 5 // 数字越小越相似, 数字为0则为完全一致.
func (bl *Baseline) FuzzyCompare(other *Baseline) bool {