nuxeo-0.3.0.3: app/Main.hs
{-# LANGUAGE OverloadedStrings #-}
module Main where
import qualified Data.Text as Text
import qualified Data.Text.IO as TIO
import Nuxeo.ElasticSearch
import Nuxeo.Log
import Options.Applicative
data NuxeoCli = NuxeoCli { cliLogFile :: String
, cliLogin :: String
, cliPassword :: String
, cliUrl :: String }
args :: Parser NuxeoCli
args = NuxeoCli
<$> option auto (long "log" <> help "Log file" <> value "server.log")
<*> option auto (long "login" <> help "Instance login")
<*> option auto (long "password" <> help "Instance password")
<*> option auto (long "url" <> help "Instance base url")
-- | Exemple to extract errors from Nuxeo log
nuxeocli :: NuxeoCli -> IO()
nuxeocli (NuxeoCli logFile login password url) = (filter (\l -> nuxeoLogEntryType l == Error) <$> parseNuxeoLog logFile)
>>= mapM_ (\t -> TIO.putStrLn $
Text.replicate 10 "=" <> "\n"
<> Text.replicate 5 " " <> (Text.pack $ show $ nuxeoLogEntryDthr t)
<> "\n" <> Text.replicate 10 "=" <> "\n"
<> (Text.pack $ show $ nuxeoLogEntryType t)
<> " - "
<> nuxeoLogEntryAction t
<> "\n\n"
<> nuxeoLogEntryLog t
)
main :: IO()
main = do
nuxeocli =<< execParser opts
where
opts = info (args <**> helper)
(fullDesc
<> progDesc "Nuxeo CLI"
<> header "nuxeo - nuxeo cli tools"
)