0 | module Evince.Config
 1 |
 2 | import Data.String
 3 | import Evince.Core
 4 |
 5 | parseNat : String -> Maybe Nat
 6 | parseNat s = do
 7 |   n <- parseInteger {a = Integer} s
 8 |   if n >= 0 then Just (cast n) else Nothing
 9 |
10 | applyArg : RunConfig -> String -> RunConfig
11 | applyArg cfg "--fail-fast"  = { failFast  := True } cfg
12 | applyArg cfg "--randomize"  = { randomize := True } cfg
13 | applyArg cfg "--times"      = { showTiming := True } cfg
14 | applyArg cfg "--rerun"      = { rerun := True } cfg
15 | applyArg cfg arg =
16 |   let (key, rest) = break (== '=') arg
17 |       val = substr 1 (length rest) rest
18 |   in if val == "" then cfg
19 |      else case key of
20 |        "--match" => { match := Just val } cfg
21 |        "--skip"  => { skip  := Just val } cfg
22 |        "--seed"  => { seed  := parseNat val } cfg
23 |        "--junit" => { junitOutput := Just val } cfg
24 |        "--jobs"  => case parseNat val of
25 |                       Just j  => { jobs := j } cfg
26 |                       Nothing => cfg
27 |        _         => cfg
28 |
29 | ||| Parse command-line arguments into a RunConfig.
30 | export
31 | parseArgs : List String -> RunConfig
32 | parseArgs = foldl applyArg defaultConfig
33 |