summaryrefslogtreecommitdiff
path: root/src/Trivstream/Options/Utils.hs
blob: 30694d8d0696a02dc3de985ad0074b2cb6dd2b18 (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
{-# LANGUAGE StandaloneDeriving #-}

module Trivstream.Options.Utils
  ( rCI
  ) where

import Options.Applicative

import Data.Char
import Data.Maybe

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]