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 - a frugal issue tracker, version 0.1.2.5\n\ \(C) 2015 Francesco Ariis - http://www.ariis.it\n\ \released under the GNU General Public License 3\n" -- todo add doc to use less -r when piping hIsTerminalDevice stdout [doc] runLentil :: LOptions -> IO () runLentil lo = uncurry findIssues (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 ord) TagPop -> outFunction (ppPopularity bCol fil) Csv -> outFunction (issues2CSV fil) Comp -> outFunction (issues2Compiler fil)