diff options
Diffstat (limited to 'src/Trivstream/Options/Utils.hs')
| -rw-r--r-- | src/Trivstream/Options/Utils.hs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/Trivstream/Options/Utils.hs b/src/Trivstream/Options/Utils.hs new file mode 100644 index 0000000..30694d8 --- /dev/null +++ b/src/Trivstream/Options/Utils.hs | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | {-# LANGUAGE StandaloneDeriving #-} | ||
| 2 | |||
| 3 | module Trivstream.Options.Utils | ||
| 4 | ( rCI | ||
| 5 | ) where | ||
| 6 | |||
| 7 | import Options.Applicative | ||
| 8 | |||
| 9 | import Data.Char | ||
| 10 | import Data.Maybe | ||
| 11 | |||
| 12 | import Network.Socket | ||
| 13 | |||
| 14 | |||
| 15 | deriving instance Enum Family | ||
| 16 | deriving instance Bounded Family | ||
| 17 | |||
| 18 | |||
| 19 | rCI :: (Show a, Read a) => ReadM a | ||
| 20 | rCI = eitherReader rRep' | ||
| 21 | where | ||
| 22 | rRep' str = case mapMaybe readMaybe $ cases str of | ||
| 23 | [] -> Left $ "Could not parse `" ++ str ++ "'" | ||
| 24 | [x] -> Right x | ||
| 25 | xs -> Left $ "Ambiguous parse for `" ++ str ++ "': " ++ show xs | ||
| 26 | cases [] = [[]] | ||
| 27 | cases (c:cs) = [(c':cs') | c' <- [toLower c, c, toUpper c], cs' <- cases cs] | ||
| 28 | |||
| 29 | rFamily :: ReadM Family | ||
| 30 | rFamily = undefined | ||
| 31 | where | ||
| 32 | families = filter isSupportedFamily [minBound..maxBound] | ||
