import Lentil.Types import Lentil.Args import Lentil.File import Lentil.Print import Lentil.Query import Lentil.Export import Options.Applicative import Data.Monoid -- 7.8 import qualified System.IO as I main :: IO () main = I.hSetBuffering I.stderr I.NoBuffering >> -- b/c progress bar execParser opts >>= runLentil where opts = info (helpOvert <*> lOpts <* version) ( fullDesc <> header "lentil - frugal issue tracker" <> footer "manual and examples: http://www.ariis.it/static/articles/lentil-manual/page.html") -- 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 :: Parser (a -> a) version = infoOption versionCopy ( long "version" <> short 'v' <> help "show version and copyright info" ) where versionCopy = "\nlentil - frugal issue tracker, version 1.0.9.1\n\ \(C) 2015-2017 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) (loFlagwords lo)) (loInExcl lo) >>= \is -> -- grab issues let fil = filterAnd (loFilters lo) is -- filtered -- ord = chainSorts fil (loSort lo) -- ordered -- 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) TagPop -> outFunction (ppPopularity bCol fil) Csv -> outFunction (issues2CSV fil) Comp -> outFunction (issues2Compiler fil) Xml -> outFunction (issues2Xml fil)