From ec23067e3e153e3598b2ea23405136131c01c167 Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Mon, 1 Aug 2022 10:43:02 +0200 Subject: [PATCH] refactor: simplify main, address reReadConfig TODO --- src/PostgREST/CLI.hs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/PostgREST/CLI.hs b/src/PostgREST/CLI.hs index fcff5efcf..b296edd1c 100644 --- a/src/PostgREST/CLI.hs +++ b/src/PostgREST/CLI.hs @@ -36,18 +36,12 @@ main installSignalHandlers runAppWithSocket CLI{cliCommand, cliPath} = do conf@AppConfig{..} <- either panic identity <$> Config.readAppConfig mempty cliPath Nothing appState <- AppState.init conf - - -- Override the config with config options from the db - -- TODO: the same operation is repeated on connectionWorker, ideally this - -- would be done only once, but dump CmdDumpConfig needs it for tests. - when configDbConfig $ reReadConfig True appState - - exec cliCommand appState - where - exec :: Command -> AppState -> IO () - exec CmdDumpConfig appState = putStr . Config.toText =<< AppState.getConfig appState - exec CmdDumpSchema appState = putStrLn =<< dumpSchema appState - exec CmdRun appState = App.run installSignalHandlers runAppWithSocket appState + case cliCommand of + CmdDumpConfig -> do + when configDbConfig $ reReadConfig True appState + putStr . Config.toText =<< AppState.getConfig appState + CmdDumpSchema -> putStrLn =<< dumpSchema appState + CmdRun -> App.run installSignalHandlers runAppWithSocket appState -- | Dump DbStructure schema to JSON dumpSchema :: AppState -> IO LBS.ByteString