summaryrefslogtreecommitdiffstats
path: root/Kirk
diff options
context:
space:
mode:
Diffstat (limited to 'Kirk')
-rw-r--r--Kirk/Config.hs61
1 files changed, 61 insertions, 0 deletions
diff --git a/Kirk/Config.hs b/Kirk/Config.hs
new file mode 100644
index 0000000..d123aab
--- /dev/null
+++ b/Kirk/Config.hs
@@ -0,0 +1,61 @@
+{-# LANGUAGE ApplicativeDo #-}
+{-# LANGUAGE RecordWildCards #-}
+
+module Kirk.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