feat: Add --example cli option to show example config file

This commit is contained in:
Wolfgang Walther
2020-12-23 19:39:40 +01:00
committed by Wolfgang Walther
parent 69b459e7b6
commit 2cbe1ba903
2 changed files with 18 additions and 17 deletions
+1 -1
View File
@@ -32,7 +32,7 @@ let
run = run =
checkedShellScript "postgrest-run" checkedShellScript "postgrest-run"
''exec ${cabal-install}/bin/cabal v2-run postgrest ${devCabalOptions} -- "$@"''; ''exec ${cabal-install}/bin/cabal v2-run ${devCabalOptions} --verbose=0 -- postgrest "$@"'';
clean = clean =
checkedShellScript "postgrest-clean" checkedShellScript "postgrest-clean"
+11 -10
View File
@@ -39,7 +39,6 @@ import qualified Data.ByteString.Base64 as B64
import qualified Data.ByteString.Char8 as BS import qualified Data.ByteString.Char8 as BS
import qualified Data.Configurator as C import qualified Data.Configurator as C
import qualified Data.Map.Strict as M import qualified Data.Map.Strict as M
import qualified Text.PrettyPrint.ANSI.Leijen as L
import Control.Lens (preview) import Control.Lens (preview)
import Control.Monad (fail) import Control.Monad (fail)
@@ -66,7 +65,6 @@ import Control.Applicative
import Data.Monoid import Data.Monoid
import Options.Applicative hiding (str) import Options.Applicative hiding (str)
import Text.Heredoc import Text.Heredoc
import Text.PrettyPrint.ANSI.Leijen hiding ((<$>), (<>))
import PostgREST.Auth (parseSecret) import PostgREST.Auth (parseSecret)
import PostgREST.Parsers (pRoleClaimKey) import PostgREST.Parsers (pRoleClaimKey)
@@ -144,19 +142,16 @@ docsVersion = "v" <> dropEnd 1 (dropWhileEnd (/= '.') prettyVersion)
readCLIShowHelp :: Environment -> IO CLI readCLIShowHelp :: Environment -> IO CLI
readCLIShowHelp env = customExecParser parserPrefs opts readCLIShowHelp env = customExecParser parserPrefs opts
where where
parserPrefs = prefs showHelpOnError parserPrefs = prefs $ showHelpOnError <> showHelpOnEmpty
opts = info (helper <*> cliParser) $ opts = info (helper <*> exampleParser <*> cliParser) $
fullDesc fullDesc
<> progDesc ( <> progDesc (
"PostgREST " "PostgREST "
<> toS prettyVersion <> toS prettyVersion
<> " / create a REST API to an existing Postgres database" <> " / create a REST API to an existing Postgres database"
) )
<> footerDoc (Just $ <> footer "To run PostgREST, please pass the FILENAME argument or set PGRST_ environment variables."
text "Example Config File:"
L.<> nest 2 (hardline L.<> exampleCfg)
)
cliParser :: Parser CLI cliParser :: Parser CLI
cliParser = CLI <$> cliParser = CLI <$>
@@ -182,9 +177,15 @@ readCLIShowHelp env = customExecParser parserPrefs opts
| M.null env = Just <$> v | M.null env = Just <$> v
| otherwise = optional v | otherwise = optional v
exampleParser :: Parser (a -> a)
exampleParser =
infoOption example (
long "example" <>
short 'e' <>
help "Show an example configuration file"
)
exampleCfg :: Doc example =
exampleCfg = vsep . map (text . toS) . lines $
[str|### REQUIRED: [str|### REQUIRED:
|db-uri = "postgres://user:pass@localhost:5432/dbname" |db-uri = "postgres://user:pass@localhost:5432/dbname"
|db-schema = "public" |db-schema = "public"