summaryrefslogtreecommitdiffstats
path: root/Kirk/Config.hs
blob: d123aab484e20bd5d9f2f57721cc359f36cf89c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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