Skip to content

Commit

Permalink
enhance probe output
Browse files Browse the repository at this point in the history
  • Loading branch information
M09Ic committed Oct 13, 2024
1 parent e483bb4 commit af82ae4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
13 changes: 8 additions & 5 deletions internal/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions pkg/baseline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit af82ae4

Please sign in to comment.