packages feed

lentil-0.1.6.2: src/Main.hs

import Lentil.Types
import Lentil.Args
import Lentil.File
import Lentil.Print
import Lentil.Query
import Lentil.Export

import Options.Applicative

import qualified Data.Maybe as M
import Data.Monoid -- 7.8
import qualified System.IO as I


main :: IO ()
main = execParser opts >>= runLentil
    where opts = info (helpOvert <*> lOpts <* version)
            ( fullDesc <>
              header "lentil - a frugal issue tracker" )

-- overt help text (even in condensed help)
helpOvert :: Parser (a -> a)
helpOvert = abortOption ShowHelpText $ mconcat [ long "help",
                                                 short 'h',
                                                 help "Show this help text" ]

version = infoOption versionCopy ( long "version" <>
                                   short 'v'      <>
                                   help "show version and copyright info" )
    where
          versionCopy = "lentil - frugal issue tracker, version 0.1.6.2\n\
                        \(C) 2015 Francesco Ariis - http://www.ariis.it\n\
                        \released under the GNU General Public License v3\n"


runLentil :: LOptions -> IO ()
runLentil lo = uncurry (findIssues (loAlias lo))
                       (loInExcl lo) >>= \is -> -- grab issues
               let fil = filterAnd (loFilters lo) is       -- filtered
                   -- ord = chainSorts fil (loSort lo)        -- ordered
                   -- todo leave sort out as now? [design]

                   -- which function to use to output stuff (file/term)
                   outFunction :: String -> IO ()
                   outFunction = case loOutFile lo of
                                   Nothing -> putStrLn
                                   Just fp -> writeFile fp

                   -- col or not?
                   bCol :: Bool
                   bCol = if loOutFile lo == Nothing
                            then True
                            else False

               in

               case loFormat lo of
                 Pretty -> outFunction (ppIssues bCol fil) -- fixme o ord?
                 TagPop -> outFunction (ppPopularity bCol fil)
                 Csv    -> outFunction (issues2CSV fil)
                 Comp   -> outFunction (issues2Compiler fil)