Skip to content

Commit 88c456b

Browse files
committed
added a warning about wrong inex keys
1 parent 3fcae08 commit 88c456b

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

src/main/scala/org/polystat/cli/Main.scala

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.polystat.cli
22

3+
import cats.data.NonEmptyList
34
import cats.effect.ExitCode
45
import cats.effect.IO
56
import cats.effect.IOApp
@@ -29,13 +30,35 @@ object Main extends IOApp:
2930
)
3031
yield exitCode
3132

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+
3246
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
3659
case Some(Exclude(exclude)) =>
3760
analyzers.mapFilter { case a =>
38-
Option.when(!exclude.contains_(a.ruleId))(a)
61+
Option.unless(exclude.contains_(a.ruleId))(a)
3962
}
4063
case Some(Include(include)) =>
4164
analyzers.mapFilter { case a =>
@@ -66,8 +89,10 @@ object Main extends IOApp:
6689
IO.println(s"Cleaning ${path.absolute}...") *>
6790
path.createDirIfDoesntExist.flatMap(_.clean)
6891
case None => Files[IO].createTempDirectory
92+
93+
filtered <- filterAnalyzers(EOAnalyzer.analyzers, inex)
6994
processedConfig = ProcessedConfig(
70-
filteredAnalyzers = filterAnalyzers(inex),
95+
filteredAnalyzers = filtered,
7196
tempDir = tempDir,
7297
output = out,
7398
input = input,

0 commit comments

Comments
 (0)