about summary refs log blame commit diff
path: root/users/aspen/xanthous/src/Xanthous/Util/Optparse.hs
blob: dfa65372351d326d49a1a3d144a3b26b250836ec (plain) (tree)




















                                                                                
--------------------------------------------------------------------------------
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