Last active
August 29, 2015 14:05
-
-
Save zilberstein/52a4e04788810e0f1ce4 to your computer and use it in GitHub Desktop.
Parse Flags Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parseFlags :: [String] -> Options -> Maybe Options | |
parseFlags (flag : flags) opts = do | |
let pieces = splitOn "=" flag | |
case pieces of | |
"--port" : arg : _ -> parseFlags flags opts{ port = read arg } | |
"--domain-socket" : arg : _ -> parseFlags flags opts{ domainSocket = read arg } | |
"--host" : arg : _ -> parseFlags flags opts{ host = arg } | |
"--transport" : arg : _ -> parseFlags flags opts{ transport = arg } | |
"--protocol" : arg : _ -> parseFlags flags opts{ protocol = getProtocol arg } | |
"-n" : arg : _ -> parseFlags flags opts{ testLoops = read arg } | |
"--h" : _ -> Nothing | |
"--help" : _ -> Nothing | |
"--ssl" : _ -> parseFlags flags opts{ ssl = True } | |
"--processor-events" : _ -> parseFlags flags opts | |
_ -> Nothing -- Invalid flag | |
parseFlags [] opts = Just opts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks