Main.hs 740 Bytes
Newer Older
1 2 3 4 5
module Main where

import Control.Monad
import Network.HTTP.Client
import Options
6 7
import Options.Generic
import Prelude
8
import Script (script)
9
import Servant.Client
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

main :: IO ()
main = do
  -- we parse CLI options
  opts@(ClientOpts (Helpful uri) _ _ (Helpful verb)) <- getRecord "Gargantext client"
  mgr <- newManager defaultManagerSettings
  burl <- parseBaseUrl uri
  when verb $ do
    putStrLn $ "[Debug] user: " ++ maybe "<none>" show (unHelpful $ user opts)
    putStrLn $ "[Debug] backend: " ++ show burl
  -- we run 'script' from the Script module, reporting potential errors
  res <- runClientM (script opts) (mkClientEnv mgr burl)
  case res of
    Left err -> putStrLn $ "[Client error] " ++ show err
    Right a  -> print a