summaryrefslogtreecommitdiff
path: root/src/Trivstream/Options/Utils.hs
blob: bab27b3e002a50df1426372ca9f58004c1c243e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{-# 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]