+ parseCLI :: [String] -> MaybeErrorString BotSettings
+ parseCLI [] = Ok
+ { bs_nick = "clooglebot"
+ , bs_nickserv = Nothing
+ , bs_autojoin = []
+ , bs_port = 6667
+ , bs_server = "irc.freenode.net"
+ }
+ parseCLI [a:as]
+ | a == "-n" || a == "--nick"
+ = arg1 "--nick" as \a c->{c & bs_nick=a}
+ | a == "-ns" || a == "--nickserv"
+ = arg1 "--nickserv" as \a c->{c & bs_nickserv=Just a}
+ | a == "-a" || a == "--autojoin"
+ = arg1 "--autojoin" as \a c->{c & bs_autojoin=c.bs_autojoin ++ [a]}
+ | a == "-p" || a == "--port"
+ = arg1 "--port" as \a c->{c & bs_port=toInt a}
+ | a == "-s" || a == "--server"
+ = arg1 "--port" as \a c->{c & bs_server=a}
+ | a == "-h" || a == "--help" = Error $ join "\n" $
+ [ "Usage: cloogle [OPTS]"
+ , "Options:"
+ , "\t--nick/-n NICKNAME Use the given nickname instead of clooglebot"
+ , "\t--nickserv/-ns PW Identify via the given password with NickServ"
+ , "\t--port/-p PORT Use the given port instead of port 6667"
+ , "\t--server/-s SERVER Use the given server instead of irc.freenode.net"
+ , "\t--autojoin/-a CHANNEL Add CHANNEL to the autojoin list. This command "
+ , "\t can be called multiple times. Beware that #"
+ , "\t has to be escaped in most shells"
+ ]
+ = Error $ "Unknown option: " +++ a
+
+ arg1 name [] _ = Error $ name +++ " requires an argument"
+ arg1 name [a:as] f = parseCLI as >>= Ok o f a
+
+ nickserv pw = PRIVMSG (CSepList ["NickServ"]) $ "IDENTIFY " +++ pw
+