]> Git — Sourcephile - gargantext.git/blob - bin/gargantext-server/Main.hs
Merge remote-tracking branch 'origin/506-dev-tree-search-fix' into dev
[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 QuasiQuotes #-}
15 {-# LANGUAGE StandaloneDeriving #-}
16 {-# LANGUAGE Strict #-}
17 {-# LANGUAGE TypeOperators #-}
18 {-# OPTIONS_GHC -fno-warn-orphans #-}
19
20
21 module Main where
22
23
24 import Data.Maybe (fromMaybe)
25 import Data.Text (unpack)
26 import Data.Version (showVersion)
27 import Database.PostgreSQL.Simple.SqlQQ (sql)
28 import GHC.IO.Exception (IOException)
29 import Gargantext.API (startGargantext, Mode(..)) -- , startGargantextMock)
30 import Gargantext.API.Admin.EnvTypes (DevEnv)
31 import Gargantext.API.Dev (withDevEnv, runCmdDev)
32 import Gargantext.Prelude
33 import Options.Generic
34 import System.Exit (exitSuccess)
35 import qualified Paths_gargantext as PG -- cabal magic build module
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 myIniFile' = case myIniFile of
74 Nothing -> panic "[ERROR] gargantext.ini needed"
75 Just i -> i
76
77 ---------------------------------------------------------------
78 let start = case myMode of
79 Mock -> panic "[ERROR] Mock mode unsupported"
80 _ -> startGargantext myMode myPort' (unpack myIniFile')
81 putStrLn $ "Starting with " <> show myMode <> " mode."
82 start
83 ---------------------------------------------------------------