{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE Unsafe #-} -- ----------------------------------------------------------------------------- -- Copyright (C) 2019, Maxim Lihachev, -- -- This program is free software: you can redistribute it and/or modify it -- under the terms of the GNU General Public License as published by the Free -- Software Foundation, version 3. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -- ----------------------------------------------------------------------------- -- -- | Json-search service -- module Main (main) where import Relude ( Maybe (Nothing), Bool (False), IO, ($), id, null ) import System.Exit ( die ) import System.Environment ( getArgs, withArgs ) import System.Console.CmdArgs ( cmdArgs, help, summary, typ, name, program, (&=) ) import Text.Pretty.Simple ( pPrint ) import Server ( startServer, ServerSettings (ServerSettings, file, cached, logs, port), checkJsonFile ) -- ----------------------------------------------------------------------------- -- -- | Default command line arguments -- defaultSettings :: IO ServerSettings defaultSettings = cmdArgs $ ServerSettings { port = 3000 &= typ "3000" &= help "Search server port" , logs = "apache" &= typ "apache" &= help "apache | simple | json | disable | full" , cached = False &= typ "False" &= help "Store Json data into memory" &= name "cached" , file = Nothing &= typ "data.json" &= help "Json file name" &= name "json" } &= program "json-search-server" &= summary "json-search-server v0.1.0: seach server for Json" -- ----------------------------------------------------------------------------- -- -- | Start application -- main :: IO () main = do args <- getArgs settings <- (if null args then withArgs ["--help"] else id) defaultSettings pPrint settings let fileStatus = checkJsonFile (file settings) in case fileStatus of "ok" -> startServer settings _err -> die fileStatus