From 7225d47e9c1f4c7032ad55fbe1d9f33ff205549c Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 2 May 2017 21:59:10 +0200 Subject: ircout: init --- Config.hs | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Config.hs (limited to 'Config.hs') diff --git a/Config.hs b/Config.hs new file mode 100644 index 0000000..fc959e1 --- /dev/null +++ b/Config.hs @@ -0,0 +1,61 @@ +{-# LANGUAGE ApplicativeDo #-} +{-# LANGUAGE RecordWildCards #-} + +module Config + ( Config(..) + , parseConfigFromArgs + ) + where + +import Data.Monoid +import Network.Socket (HostName,PortNumber) +import Options.Applicative + + +data Config = Config + { nick :: String + , msgtarget :: [String] + , server_hostname :: HostName + , server_port :: PortNumber + } + + +config :: Parser Config +config = do + nick <- strOption + ( long "nick" + <> value "ircout" + <> metavar "NICK" ) + + server_hostname <- strOption + ( long "host" + <> value "ni.r" + <> metavar "HOST" ) + + server_port <- option auto + ( long "port" + <> value 6667 + <> metavar "PORT") + + msgtarget <- some (argument str + ( metavar "TARGET..." + <> help + "List of channels and nicks. \ + \Ircout will join all channels. \ + \Users get messaged directly" + )) + + pure Config{..} + + +pinfo :: ParserInfo Config +pinfo = + info (config <**> helper) + ( fullDesc + <> progDesc "Read lines from stdin and forward them to IRC." + <> header "ircout - forward stdin to IRC" + ) + + +parseConfigFromArgs :: IO Config +parseConfigFromArgs = execParser pinfo -- cgit v1.2.3