{-# LANGUAGE StandaloneDeriving #-} module Trivstream.Options.Utils ( rCI ) where import Options.Applicative import Data.Char import Data.Maybe import Text.Read (readMaybe) import Network.Socket deriving instance Enum Family deriving instance Bounded Family rCI :: (Show a, Read a) => ReadM a rCI = eitherReader rRep' where rRep' str = case mapMaybe readMaybe $ cases str of [] -> Left $ "Could not parse `" ++ str ++ "'" [x] -> Right x xs -> Left $ "Ambiguous parse for `" ++ str ++ "': " ++ show xs cases [] = [[]] cases (c:cs) = [(c':cs') | c' <- [toLower c, c, toUpper c], cs' <- cases cs] rFamily :: ReadM Family rFamily = undefined where families = filter isSupportedFamily [minBound..maxBound]