about summary refs log tree commit diff
path: root/users/aspen/xanthous/src/Xanthous/Util/Optparse.hs
blob: dfa65372351d326d49a1a3d144a3b26b250836ec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
--------------------------------------------------------------------------------
module Xanthous.Util.Optparse
  ( readWithGuard
  ) where
--------------------------------------------------------------------------------
import Xanthous.Prelude
--------------------------------------------------------------------------------
import qualified Options.Applicative as Opt
--------------------------------------------------------------------------------

readWithGuard
  :: Read b
  => (b -> Bool)
  -> (b -> String)
  -> Opt.ReadM b
readWithGuard predicate errmsg = do
  res <- Opt.auto
  unless (predicate res)
    $ Opt.readerError
    $ errmsg res
  pure res