summaryrefslogtreecommitdiff
path: root/src/Trivstream/Options/Utils.hs
diff options
context:
space:
mode:
authorGregor Kleen <pngwjpgh@users.noreply.github.com>2016-08-02 22:42:52 +0200
committerGregor Kleen <pngwjpgh@users.noreply.github.com>2016-08-02 22:42:52 +0200
commitf31a65bcd1642b3f042bd906674f4064cfc9362c (patch)
treeb99f2180b38a2a3280f63dc9f521785fe3736578 /src/Trivstream/Options/Utils.hs
parentd6647e7fc48c6436dc74c99b4614aa2bb557ea75 (diff)
downloadtrivstream-f31a65bcd1642b3f042bd906674f4064cfc9362c.tar
trivstream-f31a65bcd1642b3f042bd906674f4064cfc9362c.tar.gz
trivstream-f31a65bcd1642b3f042bd906674f4064cfc9362c.tar.bz2
trivstream-f31a65bcd1642b3f042bd906674f4064cfc9362c.tar.xz
trivstream-f31a65bcd1642b3f042bd906674f4064cfc9362c.zip
Inital work on option parsing
Diffstat (limited to 'src/Trivstream/Options/Utils.hs')
-rw-r--r--src/Trivstream/Options/Utils.hs32
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
3module Trivstream.Options.Utils
4 ( rCI
5 ) where
6
7import Options.Applicative
8
9import Data.Char
10import Data.Maybe
11
12import Network.Socket
13
14
15deriving instance Enum Family
16deriving instance Bounded Family
17
18
19rCI :: (Show a, Read a) => ReadM a
20rCI = 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
29rFamily :: ReadM Family
30rFamily = undefined
31 where
32 families = filter isSupportedFamily [minBound..maxBound]