summaryrefslogtreecommitdiff
path: root/HsbotIrcBot
diff options
context:
space:
mode:
authorJulien Dessaux2010-08-01 17:59:02 +0200
committerJulien Dessaux2010-08-01 17:59:02 +0200
commit03795ac2f793421af9ef2e0f3bbe5295de456933 (patch)
treecb692c6af2a6e1853166cb6c65e119069be30271 /HsbotIrcBot
parentAdded configuration debug stuff. (diff)
downloadhsbot-03795ac2f793421af9ef2e0f3bbe5295de456933.tar.gz
hsbot-03795ac2f793421af9ef2e0f3bbe5295de456933.tar.bz2
hsbot-03795ac2f793421af9ef2e0f3bbe5295de456933.zip
Moved the CLI argument processing stuff in its own file.
Diffstat (limited to 'HsbotIrcBot')
-rw-r--r--HsbotIrcBot/Hsbot/Irc/CLI.hs63
-rw-r--r--HsbotIrcBot/Main.hs55
2 files changed, 64 insertions, 54 deletions
diff --git a/HsbotIrcBot/Hsbot/Irc/CLI.hs b/HsbotIrcBot/Hsbot/Irc/CLI.hs
new file mode 100644
index 0000000..4147bd1
--- /dev/null
+++ b/HsbotIrcBot/Hsbot/Irc/CLI.hs
@@ -0,0 +1,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]"
+-- }}}
+
diff --git a/HsbotIrcBot/Main.hs b/HsbotIrcBot/Main.hs
index b8fc259..8c371bd 100644
--- a/HsbotIrcBot/Main.hs
+++ b/HsbotIrcBot/Main.hs
@@ -1,12 +1,12 @@
module Main (main) where
import Control.Monad (when)
-import Prelude hiding (catch)
import System.Console.GetOpt
import System.Environment
import System.Exit
import System.IO
+import Hsbot.Irc.CLI
import Hsbot.Irc.Config
-- | Main function
@@ -27,56 +27,3 @@ main = do
ircConfig <- getIrcConfig $ optConfigFile opts
when (optDebug opts) . putStrLn $ "[hsbot-irc] Compiled config :\n" ++ (show ircConfig)
--- 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]"
--- }}}
-