Skip to content

Commit af82ae4

Browse files
committed
enhance probe output
1 parent e483bb4 commit af82ae4

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

internal/format.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,20 @@ func Format(opts Option) {
3939
group[result.Url.Host] = append(group[result.Url.Host], &result)
4040
}
4141

42-
// 分组
43-
4442
for _, results := range group {
4543
for _, result := range results {
4644
if !opts.Fuzzy && result.IsFuzzy {
4745
continue
4846
}
49-
if !opts.NoColor {
50-
logs.Log.Console(result.ColorString() + "\n")
47+
if opts.OutputProbe == "" {
48+
if !opts.NoColor {
49+
logs.Log.Console(result.ColorString() + "\n")
50+
} else {
51+
logs.Log.Console(result.String() + "\n")
52+
}
5153
} else {
52-
logs.Log.Console(result.String() + "\n")
54+
probes := strings.Split(opts.OutputProbe, ",")
55+
logs.Log.Console(result.ProbeOutput(probes) + "\n")
5356
}
5457
}
5558
}

internal/runner.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ func (r *Runner) Output(bl *pkg.Baseline) {
364364
if r.Option.Json {
365365
out = bl.ToJson()
366366
} else if len(r.Probes) > 0 {
367-
out = bl.Format(r.Probes)
367+
out = bl.ProbeOutput(r.Probes)
368368
} else if r.Color {
369369
out = bl.ColorString()
370370
} else {
@@ -385,7 +385,7 @@ func (r *Runner) Output(bl *pkg.Baseline) {
385385
} else if r.FileOutput == "full" {
386386
r.OutputFile.SafeWrite(bl.String() + "\n")
387387
} else {
388-
r.OutputFile.SafeWrite(bl.Format(strings.Split(r.FileOutput, ",")) + "\n")
388+
r.OutputFile.SafeWrite(bl.ProbeOutput(strings.Split(r.FileOutput, ",")) + "\n")
389389
}
390390

391391
r.OutputFile.SafeSync()

pkg/baseline.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,15 @@ func (bl *Baseline) Compare(other *Baseline) int {
235235
return -1
236236
}
237237

238+
func (bl *Baseline) ProbeOutput(format []string) string {
239+
var s strings.Builder
240+
for _, f := range format {
241+
s.WriteString("\t")
242+
s.WriteString(bl.Get(f))
243+
}
244+
return strings.TrimSpace(s.String())
245+
}
246+
238247
var Distance uint8 = 5 // 数字越小越相似, 数字为0则为完全一致.
239248

240249
func (bl *Baseline) FuzzyCompare(other *Baseline) bool {

0 commit comments

Comments
 (0)