]> Git — Sourcephile - gargantext.git/blob - bin/gargantext-server/Main.hs
merge done
[gargantext.git] / bin / gargantext-server / Main.hs
1 {-|
2 Module : Main.hs
3 Description : Gargantext starter
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 Script to start gargantext with different modes (Dev, Prod, Mock).
11
12 -}
13
14 {-# LANGUAGE StandaloneDeriving #-}
15 {-# LANGUAGE TypeOperators #-}
16 {-# LANGUAGE Strict #-}
17
18 module Main where
19
20 import Data.Version (showVersion)
21 import Data.Text (unpack)
22 import qualified Paths_gargantext as PG -- cabal magic build module
23 import Options.Generic
24 import System.Exit (exitSuccess)
25
26 import Gargantext.Prelude
27 import Gargantext.API (startGargantext, Mode(..)) -- , startGargantextMock)
28
29 --------------------------------------------------------
30 -- Graph Tests
31 --import qualified Gargantext.Graph.Utils as U
32 --import qualified Gargantext.Graph.Distances.Conditional as C
33 --import qualified Gargantext.Graph.Distances.Distributional as D
34 --import qualified Gargantext.Graph.Distances.Matrice as M
35 --------------------------------------------------------
36
37 instance ParseRecord Mode
38 instance ParseField Mode
39 instance ParseFields Mode
40
41 data MyOptions w =
42 MyOptions { run :: w ::: Mode
43 <?> "Possible modes: Dev | Mock | Prod"
44 , port :: w ::: Maybe Int
45 <?> "By default: 8008"
46 , ini :: w ::: Maybe Text
47 <?> "Ini-file path of gargantext.ini"
48 , version :: w ::: Bool
49 <?> "Show version number and exit"
50 }
51 deriving (Generic)
52
53 instance ParseRecord (MyOptions Wrapped)
54 deriving instance Show (MyOptions Unwrapped)
55
56
57 main :: IO ()
58 main = do
59 MyOptions myMode myPort myIniFile myVersion <- unwrapRecord
60 "Gargantext server"
61
62 if myVersion then do
63 putStrLn $ "Version: " <> showVersion PG.version
64 System.Exit.exitSuccess
65 else
66 return ()
67
68 let myPort' = case myPort of
69 Just p -> p
70 Nothing -> 8008
71
72 let start = case myMode of
73 Mock -> panic "[ERROR] Mock mode unsupported"
74 _ -> startGargantext myMode myPort' (unpack myIniFile')
75 where
76 myIniFile' = case myIniFile of
77 Nothing -> panic "[ERROR] gargantext.ini needed"
78 Just i -> i
79
80 putStrLn $ "Starting with " <> show myMode <> " mode."
81 start
82