]> Git — Sourcephile - gargantext.git/blob - bin/gargantext-server/Main.hs
[VERSION] +1 to 0.0.5.1
[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 {-# OPTIONS_GHC -fno-warn-orphans #-}
18
19 module Main where
20
21 import Data.Version (showVersion)
22 import Data.Text (unpack)
23 import qualified Paths_gargantext as PG -- cabal magic build module
24 import Options.Generic
25 import System.Exit (exitSuccess)
26
27 import Gargantext.Prelude
28 import Gargantext.API (startGargantext, Mode(..)) -- , startGargantextMock)
29
30 --------------------------------------------------------
31 -- Graph Tests
32 --import qualified Gargantext.Graph.Utils as U
33 --import qualified Gargantext.Graph.Distances.Conditional as C
34 --import qualified Gargantext.Graph.Distances.Distributional as D
35 --import qualified Gargantext.Graph.Distances.Matrice as M
36 --------------------------------------------------------
37
38 instance ParseRecord Mode
39 instance ParseField Mode
40 instance ParseFields Mode
41
42 data MyOptions w =
43 MyOptions { run :: w ::: Mode
44 <?> "Possible modes: Dev | Mock | Prod"
45 , port :: w ::: Maybe Int
46 <?> "By default: 8008"
47 , ini :: w ::: Maybe Text
48 <?> "Ini-file path of gargantext.ini"
49 , version :: w ::: Bool
50 <?> "Show version number and exit"
51 }
52 deriving (Generic)
53
54 instance ParseRecord (MyOptions Wrapped)
55 deriving instance Show (MyOptions Unwrapped)
56
57
58 main :: IO ()
59 main = do
60 MyOptions myMode myPort myIniFile myVersion <- unwrapRecord
61 "Gargantext server"
62
63 if myVersion then do
64 putStrLn $ "Version: " <> showVersion PG.version
65 System.Exit.exitSuccess
66 else
67 return ()
68
69 let myPort' = case myPort of
70 Just p -> p
71 Nothing -> 8008
72
73 let start = case myMode of
74 Mock -> panic "[ERROR] Mock mode unsupported"
75 _ -> startGargantext myMode myPort' (unpack myIniFile')
76 where
77 myIniFile' = case myIniFile of
78 Nothing -> panic "[ERROR] gargantext.ini needed"
79 Just i -> i
80
81 putStrLn $ "Starting with " <> show myMode <> " mode."
82 start
83