Main.hs 2.37 KB
Newer Older
1 2 3 4 5 6 7 8 9
{-|
Module      : Main.hs
Description : Gargantext starter
Copyright   : (c) CNRS, 2017-Present
License     : AGPL + CECILL v3
Maintainer  : team@gargantext.org
Stability   : experimental
Portability : POSIX

10
Script to start gargantext with different modes (Dev, Prod, Mock).
11

12
-}
13

14 15 16 17
{-# LANGUAGE StandaloneDeriving   #-}
{-# LANGUAGE TypeOperators        #-}
{-# LANGUAGE Strict               #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
18

19 20
module Main where

21
import Data.Version (showVersion)
22
import Data.Text (unpack)
23 24 25
import qualified Paths_gargantext as PG -- cabal magic build module
import Options.Generic
import System.Exit (exitSuccess)
26

27
import Gargantext.Prelude
28
import Gargantext.API (startGargantext, Mode(..)) -- , startGargantextMock)
29

30
--------------------------------------------------------
31 32 33 34 35
-- Graph Tests
--import qualified Gargantext.Graph.Utils                    as U
--import qualified Gargantext.Graph.Distances.Conditional    as C
--import qualified Gargantext.Graph.Distances.Distributional as D
--import qualified Gargantext.Graph.Distances.Matrice        as M
36
--------------------------------------------------------
37 38

instance ParseRecord Mode
39
instance ParseField  Mode
40 41
instance ParseFields Mode

Alexandre Delanoë's avatar
Alexandre Delanoë committed
42 43 44 45 46 47 48
data MyOptions w =
  MyOptions { run  :: w ::: Mode
                        <?> "Possible modes: Dev | Mock | Prod"
            , port :: w ::: Maybe Int
                        <?> "By default: 8008"
            , ini  :: w ::: Maybe Text
                        <?> "Ini-file path of gargantext.ini"
49 50
            , version :: w ::: Bool
                        <?> "Show version number and exit"
Alexandre Delanoë's avatar
Alexandre Delanoë committed
51 52
            }
   deriving (Generic)
53

54 55
instance ParseRecord (MyOptions Wrapped)
deriving instance Show (MyOptions Unwrapped)
56

57

58
main :: IO ()
Alexandre Delanoë's avatar
Alexandre Delanoë committed
59
main = do
60
  MyOptions myMode myPort myIniFile myVersion  <- unwrapRecord
Alexandre Delanoë's avatar
Alexandre Delanoë committed
61 62
          "Gargantext server"

63 64 65 66 67 68
  if myVersion then do
    putStrLn $ "Version: " <> showVersion PG.version
    System.Exit.exitSuccess
  else
    return ()

Alexandre Delanoë's avatar
Alexandre Delanoë committed
69 70 71 72 73
  let myPort' = case myPort of
        Just p  -> p
        Nothing -> 8008

  let start = case myMode of
74 75
        Mock -> panic "[ERROR] Mock mode unsupported"
        _ -> startGargantext myMode myPort' (unpack myIniFile')
Alexandre Delanoë's avatar
Alexandre Delanoë committed
76 77 78 79 80 81 82
            where
              myIniFile' = case myIniFile of
                  Nothing -> panic "[ERROR] gargantext.ini needed"
                  Just i  -> i

  putStrLn $ "Starting with " <> show myMode <> " mode."
  start