packages feed

lentil-0.1.1.3: 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


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 = "\nlentil - a frugal issue tracker, version 0.1.1.3\n\
                        \(C) 2015 Francesco Ariis - http://www.ariis.it\n\
                        \released under the GNU General Public License 3\n"


runLentil :: LOptions -> IO ()
runLentil lo = uncurry findIssues (loInExcl lo) >>= \is -> -- grab issues
               let fil = filterAnd (loFilters lo) is       -- filtered
                   ord = chainSorts fil (loSort lo) in     -- ordered

               case loOutFile lo of

                 -- std output
                 Nothing -> case loFormat lo of
                              Csv    -> putStrLn (issues2CSV is)
                              Pretty -> putStrLn (ppIssues True ord)
                              TagPop -> putStrLn (ppPopularity True is)

                 Just fp -> case loFormat lo of
                              Csv    -> writeFile fp (issues2CSV is)
                              Pretty -> writeFile fp (ppIssues False ord)
                              TagPop -> writeFile fp (ppPopularity False is)