Merge pull request #10771 from alt-romes/wip/romes/10686
[cabal.git] / cabal-validate / src / Step.hs
blob801b660f5cc96a09cf545987dc7520ab72a8ac5e
1 -- | The steps that can be run by @cabal-validate@.
2 module Step
3 ( Step (..)
4 , displayStep
5 , nameToStep
6 , parseStep
7 ) where
9 import Data.Map.Strict (Map)
10 import qualified Data.Map.Strict as Map
12 -- | A step to be run by @cabal-validate@.
13 data Step
14 = Build
15 | Doctest
16 | LibTests
17 | LibSuite
18 | LibSuiteExtras
19 | CliTests
20 | CliSuite
21 | SolverBenchmarksTests
22 | SolverBenchmarksRun
23 deriving (Eq, Enum, Bounded, Show)
25 -- | Get the display identifier for a given `Step`.
27 -- This is used to parse the @--step@ command-line argument.
29 -- Note that these names are just kebab-case variants of the `Step` constructor
30 -- names; they do not attempt to describe the steps.
31 displayStep :: Step -> String
32 displayStep step =
33 case step of
34 Build -> "build"
35 Doctest -> "doctest"
36 LibTests -> "lib-tests"
37 LibSuite -> "lib-suite"
38 LibSuiteExtras -> "lib-suite-extras"
39 CliTests -> "cli-tests"
40 CliSuite -> "cli-suite"
41 SolverBenchmarksTests -> "solver-benchmarks-tests"
42 SolverBenchmarksRun -> "solver-benchmarks-run"
44 -- | A map from step names to `Steps`.
46 -- This is an inverse of `displayStep`.
47 nameToStep :: Map String Step
48 nameToStep =
49 Map.fromList
50 [ (displayStep step, step)
51 | step <- [minBound .. maxBound]
54 -- | Parse a string as a `Step`.
55 parseStep :: String -> Maybe Step
56 parseStep step = Map.lookup step nameToStep