summaryrefslogtreecommitdiff
path: root/HsbotIrcBot/Hsbot/Irc/CLI.hs
blob: 4147bd181a031564bb7869387711ce81dfeae4e9 (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
62
63
module Hsbot.Irc.CLI
    ( Options (..)
    , defaultOptions
    , header
    , options
    ) where

import System.Console.GetOpt
import System.Exit

-- CLI argument parting stuff {{{
-- | CLI options
data Options = Options
    { optDebug      :: Bool
    , optConfigFile :: Maybe String
    , optGroup      :: Maybe String
    , optUser       :: Maybe String
    , optVerbose    :: Bool
    } deriving (Show)

-- | CLI default options
defaultOptions :: Options
defaultOptions = Options { optDebug      = False
                         , optConfigFile = Nothing
                         , optGroup      = Nothing
                         , optUser       = Nothing
                         , optVerbose    = False }

-- | CLI options logic
options :: [ OptDescr (Options -> IO Options) ]
options =
    [ Option "d" ["debug"]
        (NoArg (\opt -> return opt { optDebug = True, optVerbose = True }))
        "Enter verbose debug mode and prevents Hsbot from forking in background"
    , Option "f" ["file"]
        (ReqArg (\arg opt -> return opt { optConfigFile = return arg }) "<config_file>")
        "The config file to use"
    , Option "g" ["group"]
        (ReqArg (\arg opt -> return opt { optGroup = return arg }) "<group>")
        "The group hsbot will run as"
    , Option "h" ["help"]
        (NoArg (\_ -> do
                    putStrLn $ usageInfo header options
                    exitWith ExitSuccess))
        "Print this help message"
    , Option "u" ["user"]
        (ReqArg (\arg opt -> return opt { optUser = return arg }) "<user>")
        "The user hsbot will run as"
    , Option "v" ["verbose"]
        (NoArg (\opt -> return opt { optVerbose = True }))
        "Enable verbose messages"
    , Option "V" ["version"]
        (NoArg (\_ -> do
                    putStrLn "hsbot-irc version 0.3"
                    exitWith ExitSuccess))
        "Show version"
    ]

-- | Usage header
header :: String
header = "Usage: hsbot-irc [-dhvV] [-f config_file] [-u user] [-g group]"
-- }}}