packages feed

boomange 0.1.1.1 → 0.1.2.0

raw patch · 2 files changed

+81/−2 lines, 2 files

Files

Main.hs view
@@ -24,6 +24,7 @@ import System.Environment import System.FilePath import Data.List+import Text.Printf  import Paths_boomange -- automatically generated @@ -34,6 +35,7 @@ import Data.Loader	  appName = "boomange"+appVersion = "0.1.2.0" -- header to be used on the sample config file configHeader =   "# This is the configuration file for " ++ appName ++ "\n" ++@@ -66,6 +68,8 @@   hPutStr final footer   hClose final +  printf "Output written to %s\n" (outputFile config)+ -- | gets the directory where configuration files should be placed -- -- First, checks if XDG_CONFIG_HOME exists, producing $XDG_CONFIG_HOME/appName if it does@@ -139,8 +143,82 @@      hPutStr hBookmarks bookmarksHeader      hPutStr hBookmarks $ sampleBookmarks      hClose hBookmarks-	+     +data Action = Help | ConfigFile String | Version | Status | Invalid String | Generate deriving Eq+parseArgs args = case args of+  "-h":r            -> Help : parseArgs r+  "--help":r        -> Help : parseArgs r+  "-c":file:r       -> ConfigFile file : parseArgs r+  "--config":file:r -> ConfigFile file : parseArgs r+  "-v":r            -> Version : parseArgs r+  "--version":r     -> Version : parseArgs r+  "-s":r            -> Status : parseArgs r+  "--status":r      -> Status : parseArgs r+  []                -> []+  other:r           -> Invalid other : Help : parseArgs r++execute [] _ = return ()+execute (h:r) configFiles =+  case h of+    Help -> do+      printf "usage: %s [OPTION...]\n" appName+      putStr $+        "Options:\n" +++        "\t-h, --help           shows this help text\n" +++        "\t-c, --config <file>  uses <file> as config instead of the default\n" +++        "\t-v, --version        outputs version and exits\n"+++        "\t-s, --status         outputs configuration file info and exits\n"+    Version -> do+      printf "%s %s\n" appName appVersion+      putStr $  "Copyright (C) 2013,2014 Marcelo Garlet Millani\n" +++        "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n" +++        "This is free software: you are free to change and redistribute it.\n" +++        "There is NO WARRANTY, to the extent permitted by law.\n"+    Status ->+      mapM showStatus configFiles >>= mapM_ (mapM_ putStrLn)+    Invalid opt -> do+      printf "'%s' is not a valid option or has an incorrect number of arguments\n" opt+    Generate -> do+      configs <- mapM loadConfig configFiles+      mapM_ generateBookmarks configs+  >> execute r configFiles++showStatus :: String -> IO [String]+showStatus configFile = do+  config <- loadConfig configFile  +  return $ printf "%s:" configFile :+    (printf "\tOutput file:\n\t\t%s" (outputFile config)) :+    (printf "\tHeader file:\n\t\t%s" (headerFile config)) :+    (printf "\tFooter file:\n\t\t%s" (footerFile config)) :+    "\tBookmarks files:" :+    (map (\x -> "\t\t" ++ x) $ watch config)++separateConfigs [] = ([],[])+separateConfigs (h:r) =+  let (actions, configs) = separateConfigs r in+  case h of+    ConfigFile x -> (actions, x : configs)+    other        -> (other : actions, configs)+  + main = do+  args <- getArgs+  let (argActions, argConfigs) = separateConfigs $ parseArgs args+      -- if help or version were asked, does not generate bookmarks+      actions =  if elem Help argActions || elem Version argActions || elem Status argActions then argActions else (Generate : argActions)+  -- if no configuration file was given, uses the default one+  configs <- if argConfigs == [] then do+    cDir <- getConfigDirectory appName+    -- if the configuration directory does not exists, sets it up+    confExists <- doesDirectoryExist cDir+    when (not confExists) $ do+      createDirectoryIfMissing True cDir+      installConfig cDir+    return $ [cDir ++ "/config"]+             else (return argConfigs)+  execute actions configs+  +{-     cDir <- getConfigDirectory appName   -- if the configuration directory does not exists, sets it up   confExists <- doesDirectoryExist cDir@@ -150,3 +228,4 @@   let cFile = cDir ++ "/config"   config <- loadConfig cFile   generateBookmarks config+-}
boomange.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                boomange-version:             0.1.1.1+version:             0.1.2.0 synopsis:            A Bookmarks manager with a HTML generator description:         In order to allow a unified and customized bookmarks file, boomange generates a HTML file with an user's bookmarks. license:             GPL-3