|
1 | 1 | package cmd
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "errors" |
5 | 4 | "fmt"
|
6 | 5 | "log"
|
7 | 6 | "os"
|
8 | 7 | "sort"
|
9 | 8 | "strings"
|
10 | 9 | "sync"
|
11 | 10 |
|
12 |
| - "github.com/MakeNowJust/heredoc" |
13 | 11 | "github.com/aquasecurity/go-dep-parser/pkg/io"
|
14 | 12 | parser_io "github.com/aquasecurity/go-dep-parser/pkg/io"
|
15 | 13 | "github.com/aquasecurity/go-dep-parser/pkg/types"
|
16 |
| - "github.com/fatih/color" |
17 | 14 | dart "github.com/kyoshidajp/dep-doctor/cmd/dart/pub"
|
18 | 15 | erlang_elixir "github.com/kyoshidajp/dep-doctor/cmd/erlang_elixir/hex"
|
19 | 16 | "github.com/kyoshidajp/dep-doctor/cmd/github"
|
@@ -181,6 +178,11 @@ func Diagnose(d Doctor, r io.ReadSeekCloserAt, year int, ignores []string) map[s
|
181 | 178 | return diagnoses
|
182 | 179 | }
|
183 | 180 |
|
| 181 | +func Report(diagnoses map[string]Diagnosis, strict_mode bool) error { |
| 182 | + reporter := NewStdoutReporter(diagnoses, strict_mode) |
| 183 | + return reporter.Report() |
| 184 | +} |
| 185 | + |
184 | 186 | type Options struct {
|
185 | 187 | packageManager string
|
186 | 188 | filePath string
|
@@ -270,72 +272,3 @@ func init() {
|
270 | 272 | fmt.Println(err.Error())
|
271 | 273 | }
|
272 | 274 | }
|
273 |
| - |
274 |
| -func Report(diagnoses map[string]Diagnosis, strict_mode bool) error { |
275 |
| - errMessages, warnMessages, ignoredMessages := []string{}, []string{}, []string{} |
276 |
| - errCount, warnCount, infoCount := 0, 0, 0 |
277 |
| - unDiagnosedCount, ignoredCount := 0, 0 |
278 |
| - |
279 |
| - lib_names := make([]string, 0, len(diagnoses)) |
280 |
| - for key := range diagnoses { |
281 |
| - lib_names = append(lib_names, key) |
282 |
| - } |
283 |
| - sort.Strings(lib_names) |
284 |
| - |
285 |
| - for _, lib_name := range lib_names { |
286 |
| - diagnosis := diagnoses[lib_name] |
287 |
| - if diagnosis.Ignored { |
288 |
| - ignoredMessages = append(ignoredMessages, fmt.Sprintf("[info] %s (ignored):", diagnosis.Name)) |
289 |
| - ignoredCount += 1 |
290 |
| - infoCount += 1 |
291 |
| - continue |
292 |
| - } |
293 |
| - |
294 |
| - if diagnosis.Error != nil { |
295 |
| - errMessages = append(errMessages, fmt.Sprintf("[error] %s: %s", diagnosis.Name, diagnosis.Error)) |
296 |
| - errCount += 1 |
297 |
| - continue |
298 |
| - } |
299 |
| - |
300 |
| - if !diagnosis.Diagnosed { |
301 |
| - warnMessages = append(warnMessages, fmt.Sprintf("[warn] %s (unknown): %s", diagnosis.Name, diagnosis.ErrorMessage())) |
302 |
| - unDiagnosedCount += 1 |
303 |
| - warnCount += 1 |
304 |
| - continue |
305 |
| - } |
306 |
| - if diagnosis.Archived { |
307 |
| - errMessages = append(errMessages, fmt.Sprintf("[error] %s (archived): %s", diagnosis.Name, diagnosis.URL)) |
308 |
| - errCount += 1 |
309 |
| - } |
310 |
| - if !diagnosis.IsActive { |
311 |
| - warnMessages = append(warnMessages, fmt.Sprintf("[warn] %s (not-maintained): %s", diagnosis.Name, diagnosis.URL)) |
312 |
| - warnCount += 1 |
313 |
| - } |
314 |
| - } |
315 |
| - |
316 |
| - fmt.Printf("\n") |
317 |
| - if len(ignoredMessages) > 0 { |
318 |
| - fmt.Println(strings.Join(ignoredMessages, "\n")) |
319 |
| - } |
320 |
| - if len(warnMessages) > 0 { |
321 |
| - color.Yellow(strings.Join(warnMessages, "\n")) |
322 |
| - } |
323 |
| - if len(errMessages) > 0 { |
324 |
| - color.Red(strings.Join(errMessages, "\n")) |
325 |
| - } |
326 |
| - |
327 |
| - color.Green(heredoc.Docf(` |
328 |
| - Diagnosis completed! %d libraries. |
329 |
| - %d error, %d warn (%d unknown), %d info (%d ignored)`, |
330 |
| - len(diagnoses), |
331 |
| - errCount, |
332 |
| - warnCount, unDiagnosedCount, |
333 |
| - infoCount, ignoredCount), |
334 |
| - ) |
335 |
| - |
336 |
| - if len(errMessages) > 0 || strict_mode && warnCount > 0 { |
337 |
| - return errors.New("has error") |
338 |
| - } |
339 |
| - |
340 |
| - return nil |
341 |
| -} |
0 commit comments