|
1 | 1 | package org.polystat.cli |
2 | 2 |
|
| 3 | +import cats.data.NonEmptyList |
3 | 4 | import cats.effect.ExitCode |
4 | 5 | import cats.effect.IO |
5 | 6 | import cats.effect.IOApp |
@@ -29,13 +30,35 @@ object Main extends IOApp: |
29 | 30 | ) |
30 | 31 | yield exitCode |
31 | 32 |
|
| 33 | + def warnMissingKeys( |
| 34 | + givenKeys: List[String], |
| 35 | + availableKeys: List[String], |
| 36 | + ): IO[Unit] = |
| 37 | + givenKeys.traverse_(rule => |
| 38 | + if availableKeys.contains(rule) then IO.unit |
| 39 | + else |
| 40 | + IO.println( |
| 41 | + s"WARNING: The analyzer with the key '$rule' does not exist. " + |
| 42 | + s"Run 'polystat list' to get the list of the available keys." |
| 43 | + ) |
| 44 | + ) |
| 45 | + |
32 | 46 | def filterAnalyzers( |
33 | | - inex: Option[IncludeExclude] |
34 | | - ): List[EOAnalyzer] = |
35 | | - inex match |
| 47 | + availableAnalyzers: List[EOAnalyzer], |
| 48 | + inex: Option[IncludeExclude], |
| 49 | + ): IO[List[EOAnalyzer]] = |
| 50 | + val givenKeys = inex |
| 51 | + .map { |
| 52 | + case Include(list) => list.toList |
| 53 | + case Exclude(list) => list.toList |
| 54 | + } |
| 55 | + .getOrElse(List()) |
| 56 | + |
| 57 | + for _ <- warnMissingKeys(givenKeys, availableAnalyzers.map(_.ruleId)) |
| 58 | + yield inex match |
36 | 59 | case Some(Exclude(exclude)) => |
37 | 60 | analyzers.mapFilter { case a => |
38 | | - Option.when(!exclude.contains_(a.ruleId))(a) |
| 61 | + Option.unless(exclude.contains_(a.ruleId))(a) |
39 | 62 | } |
40 | 63 | case Some(Include(include)) => |
41 | 64 | analyzers.mapFilter { case a => |
@@ -66,8 +89,10 @@ object Main extends IOApp: |
66 | 89 | IO.println(s"Cleaning ${path.absolute}...") *> |
67 | 90 | path.createDirIfDoesntExist.flatMap(_.clean) |
68 | 91 | case None => Files[IO].createTempDirectory |
| 92 | + |
| 93 | + filtered <- filterAnalyzers(EOAnalyzer.analyzers, inex) |
69 | 94 | processedConfig = ProcessedConfig( |
70 | | - filteredAnalyzers = filterAnalyzers(inex), |
| 95 | + filteredAnalyzers = filtered, |
71 | 96 | tempDir = tempDir, |
72 | 97 | output = out, |
73 | 98 | input = input, |
|
0 commit comments