diff options
author | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2016-08-02 22:42:52 +0200 |
---|---|---|
committer | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2016-08-02 22:42:52 +0200 |
commit | f31a65bcd1642b3f042bd906674f4064cfc9362c (patch) | |
tree | b99f2180b38a2a3280f63dc9f521785fe3736578 /src/Trivstream/Options | |
parent | d6647e7fc48c6436dc74c99b4614aa2bb557ea75 (diff) | |
download | trivstream-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')
-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] | ||