about summary refs log tree commit diff
path: root/users/glittershark/xanthous/src/Xanthous/Util/Optparse.hs
--------------------------------------------------------------------------------
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