summaryrefslogtreecommitdiff
path: root/Main.hs
diff options
context:
space:
mode:
authorJulien Dessaux2010-05-16 00:01:00 +0200
committerJulien Dessaux2010-05-16 00:01:00 +0200
commitc1662ba7b982a8502dc9f32031b7cb518df7f60e (patch)
treef00dbd9cb39bf0fbc20949105ea2b93d9e868070 /Main.hs
parentAdded the quote module. (diff)
downloadhsbot-0.2.0.tar.gz
hsbot-0.2.0.tar.bz2
hsbot-0.2.0.zip
Rewrote nearly everything!v0.2.0
* Rewrote the whole architecture to achieve extreme modularity * Added the ability to build a multiprotocol bot * Added cabal integration * Added configuration handling the XMonad style * Added configuration in ~/.hsbot * Refactored many many named and functions * Refactored data structures * Cleaned a big bunch of stuff
Diffstat (limited to '')
-rw-r--r--Main.hs55
1 files changed, 52 insertions, 3 deletions
diff --git a/Main.hs b/Main.hs
index 982c699..5e528ca 100644
--- a/Main.hs
+++ b/Main.hs
@@ -1,9 +1,58 @@
-module Main where
+module Main (main) where
-import Hsbot
+import Control.Monad (when)
+import Prelude hiding (catch)
+import System.Directory
+import System.Environment
+import System.Exit
+import System.FilePath
+import System.Info
+import System.IO
+import System.Posix.Process (executeFile)
+import System.Process
-- | Dynamic launching function
main :: IO ()
main = do
- imain
+ args <- getArgs
+ case args of
+ [] -> buildLaunch
+ ["--help"] -> usage
+ _ -> fail "unrecognized flags"
+
+usage :: IO ()
+usage = do
+ self <- getProgName
+ putStr . unlines $
+ concat ["Usage: ", self, " [OPTION]"] :
+ "Options:" :
+ " --help : Print this message" :
+ []
+
+buildLaunch :: IO ()
+buildLaunch = do
+ _ <- recompile
+ dir <- getAppUserDataDirectory "hsbot"
+ args <- getArgs
+ _ <- executeFile (dir ++ "/hsbot-" ++ arch ++ "-" ++ os) False args Nothing
+ return ()
+
+recompile :: IO (Bool)
+recompile = do
+ dir <- getAppUserDataDirectory "hsbot"
+ let binn = "hsbot-"++arch++"-"++os
+ base = dir </> "hsbot"
+ err = base ++ ".errors"
+ src = base ++ ".hs"
+ errorHandle <- openFile err WriteMode
+ exitCode <- waitForProcess =<< runProcess "ghc" ["--make", "hsbot.hs", "-fforce-recomp", "-XScopedTypeVariables", "-o", binn] (Just dir)
+ Nothing Nothing Nothing (Just errorHandle)
+ hClose errorHandle
+ when (exitCode /= ExitSuccess) $ do
+ ghcErr <- readFile err
+ let msg = unlines $
+ ["Error detected while loading hsbot configuration file: " ++ src]
+ ++ lines ghcErr ++ ["","Please check the file for errors."]
+ hPutStrLn stderr msg
+ return (exitCode == ExitSuccess)