-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add CLI to docs #3321
add CLI to docs #3321
Conversation
src/PostgREST/CLI.hs
Outdated
exampleParser :: O.Parser CLI | ||
exampleParser = | ||
CLIExample | ||
<$> showExample | ||
<*> exampleConfig | ||
|
||
exampleConfig = | ||
O.strArgument $ | ||
O.metavar "ExampleType" | ||
<> O.help "Type of config file/db/env" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing this does not show ExampleType
as a parameter of --example
and it shows these options instead:
Usage: postgrest [-v|--version]
[[-e|--example] ExampleType |
[--dump-config | --dump-schema-cache] [FILENAME]]
When it should look something like:
Usage: postgrest-12.0.2 [-v|--version] [-e|--example EXAMPLETYPE]
[--dump-config | --dump-schema] [FILENAME]
You'll need to use directly strOption
or strArgument
(not sure which is better) and add file
as a default value to avoid breaking changes. Here's an example on how to use this: https://www.fpcomplete.com/haskell/library/optparse-applicative/
I think the commit should be split into two: One adds a feature ( |
@laurenceisla How about the interface now? It is as best as I could make yet. The only problem is that |
src/PostgREST/CLI.hs
Outdated
| | ||
|PGRST_ADMIN_SERVER_PORT: 3001 | ||
|] | ||
exampleConfig _ = "print error" -- unreachable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to avoid those "unreachable" lines with proper typing. Instead of [char]
, the argument should have a type like data ExampleType = ExampleFile | ExampleDB | ExampleEnv
.
src/PostgREST/CLI.hs
Outdated
data CLI = CLI | ||
data CLIOpts = CLIOpts | ||
{ example :: Example | ||
, command :: Commands | ||
} | ||
|
||
type Example = [Char] | ||
|
||
data Commands = Commands | ||
{ cliCommand :: Command | ||
, cliPath :: Maybe FilePath | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This typing is not very good - it leaves many invalid combinations possible. You could pass both a Command
and a value for --example
at the same time, for example. And it's not even possible to pass no example option?
I think you should leave things here untouched and promote --example
to be a regular Command
:
data Command
= CmdRun
| CmdDumpConfig
| CmdDumpSchema
| CmdExample ExampleType
data ExampleType = ExampleFile | ExampleDB | ExampleEnv
Then build the parser accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with adding CmdExample ExampleType
to Command
is that this is a value option. The other enums CmdDumpConfig
and CmdDumpSchema
are handled as flags. Combining them will complicate things in implementation as well. But maybe it is doable. I'll try this and get back to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also using this would make the interface help
look like this:
Usage: postgrest-12.0.2 [-v|--version]
[--example EXAMPLETYPE | --dump-config | --dump-schema] [FILENAME]
instead of this more nice looking one:
Usage: postgrest-12.0.2 [-v|--version] [-e|--example EXAMPLETYPE]
[--dump-config | --dump-schema] [FILENAME]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also using this would make the interface help look like this:
Usage: postgrest-12.0.2 [-v|--version] [--example EXAMPLETYPE | --dump-config | --dump-schema] [FILENAME]
This means that --example EXAMPLETYPE
, --dump-config
and --dump-schema
are mutually exclusive, which makes sense now. Before, you could do something like:
postgrest --example --dump-config
# or
postgrest --dump-config --example
And it will ignore the --dump-config
and print the example directly. But now that --example
has an argument, it complicates things as Wolfgang mentioned. So I think it's OK to have them mutually exclusive like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@laurenceisla I think the above is not possible to implement as it is inconsistent. Adding an argument option in Command
that was previously just enum does not work.
As I have looked further into this, a pattern like:
data Command
= ...
| CmdExample ExampleType
| Something Argument
is used in subparsers. ref. Hence, implementing the above is inconsistent if not impossible. How about using subparsers to lift the interface something like:
$ postgrest dump [--dump-config | --dump-schema-cache]
$ postgrest example [--file | --db | --env]
I think it seems much simpler, extendible and easier to implement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the above is not possible to implement as it is inconsistent.
Hm. The inconsistency seems to be that with my proposal it would be possible to add a config file name to the "example" command. Which doesn't make sense either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using subparsers to lift the interface something like:
$ postgrest dump [--dump-config | --dump-schema-cache] $ postgrest example [--file | --db | --env]
This doesn't consider the FILENAME argument for the config file, which should be there in both the dump
commands and the run
commands (which is the default if nothing is provided), but not in the example case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@laurenceisla
I have made the interface like you said earlier:
Usage: postgrest-12.0.2 [-v|--version]
[--example EXAMPLETYPE | --dump-config | --dump-schema] [FILENAME]
Please confirm and review this design so I can move to testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argh... this gets complicated due to the need of a parameter and default values for the --example
. It's in conflict with the CLI
type expected by the parser and generates the problems that both of you encountered along the way.
How about using subparsers to lift the interface something like:
I think this may be the way to go in the future. It would need a rework of the CLI, I suppose.
Please confirm and review this design so I can move to testing.
I'm sorry to keep going back and forth but what if, instead of using an option with value, we do the same as with --dump-*
. I mean, to use:
--example-file
, --example-env
, --example-db
.
This would work as an extension of the already used --example
and wouldn't change nor break the way the CLI is currently used. The drawback is that it's more verbose (and maybe the --example
alone may be confusing since it returns the file by default?)
@taimoorzaeem @wolfgangwalther WDYT? I'm adding how the parsing would go in a review below: #3321 (review)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is how my suggestion in #3321 (comment) would be implemented (other minor changes may be needed too). It returns the following:
Usage: postgrest [-v|--version]
[(-e|--example|--example-file) | --example-env | --example-db]
[--dump-config | --dump-schema-cache] [FILENAME]
src/PostgREST/CLI.hs
Outdated
| CmdExample ExampleType | ||
|
||
data ExampleType = ExampleFile | ExampleDb | ExampleEnv |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| CmdExample ExampleType | |
data ExampleType = ExampleFile | ExampleDb | ExampleEnv | |
data Example = ExampleFile | ExampleDb | ExampleEnv |
src/PostgREST/CLI.hs
Outdated
@@ -82,7 +87,8 @@ readCLIShowHelp = | |||
where | |||
prefs = O.prefs $ O.showHelpOnError <> O.showHelpOnEmpty | |||
opts = O.info parser $ O.fullDesc <> progDesc | |||
parser = O.helper <*> versionFlag <*> exampleParser <*> cliParser | |||
-- TODO: use subparser for mulitple commands | |||
parser = O.helper <*> versionFlag <*> cliParser |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parser = O.helper <*> versionFlag <*> cliParser | |
parser = O.helper <*> versionFlag <*> exampleParser <*> cliParser |
src/PostgREST/CLI.hs
Outdated
parseExampleType :: O.ReadM Command | ||
parseExampleType = O.maybeReader $ readString . map toLower | ||
where | ||
readString "file" = Just $ CmdExample ExampleFile | ||
readString "db" = Just $ CmdExample ExampleDb | ||
readString "env" = Just $ CmdExample ExampleEnv | ||
readString _ = Just $ CmdExample ExampleFile -- default "file" | ||
|
||
|
||
dumpExampleConfigFile = | ||
O.option parseExampleType $ | ||
O.long "example" | ||
<> O.short 'e' | ||
<> O.metavar "EXAMPLETYPE" | ||
<> O.help "Type of config file/db/env" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parseExampleType :: O.ReadM Command | |
parseExampleType = O.maybeReader $ readString . map toLower | |
where | |
readString "file" = Just $ CmdExample ExampleFile | |
readString "db" = Just $ CmdExample ExampleDb | |
readString "env" = Just $ CmdExample ExampleEnv | |
readString _ = Just $ CmdExample ExampleFile -- default "file" | |
dumpExampleConfigFile = | |
O.option parseExampleType $ | |
O.long "example" | |
<> O.short 'e' | |
<> O.metavar "EXAMPLETYPE" | |
<> O.help "Type of config file/db/env" | |
exampleParser = | |
exampleParserFile <|> exampleParserEnv <|> exampleParserDb | |
exampleParserFile = | |
O.infoOption (exampleConfig ExampleFile) $ | |
O.long "example" | |
<> O.long "example-file" | |
<> O.short 'e' | |
<> O.help "Show an example of a configuration file" | |
exampleParserEnv = | |
O.infoOption (exampleConfig ExampleEnv) $ | |
O.long "example-env" | |
<> O.help "Show an example of environment variables configuration" | |
exampleParserDb = | |
O.infoOption (exampleConfig ExampleDb) $ | |
O.long "example-db" | |
<> O.help "Show an example of in-database configuration" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I'd remove -e
and --example
. It's not like those are heavily used options, that need shortcuts - we can be explicit here.
945e55d
to
a2c003f
Compare
|## Number of open connections in the pool | ||
|ALTER ROLE authenticator SET pgrst.db_pool = '10'; | ||
| | ||
|## Time in seconds to wait to acquire a slot from the connection pool | ||
|# ALTER ROLE authenticator SET pgrst.db_pool_acquisition_timeout = '10'; | ||
| | ||
|## Time in seconds after which to recycle pool connections | ||
|# ALTER ROLE authenticator SET pgrst.db_pool_max_lifetime = '1800'; | ||
| | ||
|## Time in seconds after which to recycle unused pool connections | ||
|# ALTER ROLE authenticator SET pgrst.db_pool_max_idletime = '30'; | ||
| | ||
|## Allow automatic database connection retrying | ||
|# ALTER ROLE authenticator SET pgrst.db_pool_automatic_recovery = 'true'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, these don't work. The available in-db settings are the ones here
postgrest/src/PostgREST/Config/Database.hs
Lines 45 to 71 in 85a4e35
dbSettingsNames :: [Text] | |
dbSettingsNames = | |
(prefix <>) <$> | |
["db_aggregates_enabled" | |
,"db_anon_role" | |
,"db_pre_config" | |
,"db_extra_search_path" | |
,"db_max_rows" | |
,"db_plan_enabled" | |
,"db_pre_request" | |
,"db_prepared_statements" | |
,"db_root_spec" | |
,"db_schemas" | |
,"db_tx_end" | |
,"jwt_aud" | |
,"jwt_role_claim_key" | |
,"jwt_secret" | |
,"jwt_secret_is_base64" | |
,"jwt_cache_max_lifetime" | |
,"openapi_mode" | |
,"openapi_security_active" | |
,"openapi_server_proxy_uri" | |
,"raw_media_types" | |
,"server_cors_allowed_origins" | |
,"server_trace_header" | |
,"server_timing_enabled" | |
] |
These commands show the example configuration file of the selected type. | ||
|
||
|
||
Config or Schema Cache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about separating these? One section for config and another for the scache.
$ postgrest [--example-db] | ||
$ postgrest [--example-env] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@taimoorzaeem Btw, if you'd like you could split this and do another PR with just the docs commit. That one is already mergeable.
Of course you'd need to remove the --example-db/--example/env
in that commit since they belong to this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, you're right. That would be much more manageable. Closing this PR. I would create 2 new PRs one after another for this change.
Fixes #3248.