diff options
author | Irina Truong <i.chernyavska@gmail.com> | 2021-02-12 21:09:38 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-12 21:09:38 -0800 |
commit | a3287c4ab2cea5ba5bef495e1174b12c3b2ae084 (patch) | |
tree | 2f9ebfe6f6312ad6c7b37ee8b17233ff72d1ed2f /pgcli/main.py | |
parent | 762fb4b8da98fdf6792e6c5586060ed37224f894 (diff) |
Finer control over destructive warning. (#1242)
* Finer control over destructive warning.
* Review feedback.
* Changelog.
* Run integration tests with --warn=moderate.
* Fix typo.
* Black.
Diffstat (limited to 'pgcli/main.py')
-rw-r--r-- | pgcli/main.py | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/pgcli/main.py b/pgcli/main.py index 7ab973a2..539ba449 100644 --- a/pgcli/main.py +++ b/pgcli/main.py @@ -201,8 +201,11 @@ class PGCli: self.syntax_style = c["main"]["syntax_style"] self.cli_style = c["colors"] self.wider_completion_menu = c["main"].as_bool("wider_completion_menu") - c_dest_warning = c["main"].as_bool("destructive_warning") - self.destructive_warning = c_dest_warning if warn is None else warn + self.destructive_warning = warn or c["main"]["destructive_warning"] + # also handle boolean format of destructive warning + self.destructive_warning = {"true": "all", "false": "off"}.get( + self.destructive_warning.lower(), self.destructive_warning + ) self.less_chatty = bool(less_chatty) or c["main"].as_bool("less_chatty") self.null_string = c["main"].get("null_string", "<null>") self.prompt_format = ( @@ -389,7 +392,10 @@ class PGCli: except OSError as e: return [(None, None, None, str(e), "", False, True)] - if self.destructive_warning and confirm_destructive_query(query) is False: + if ( + self.destructive_warning != "off" + and confirm_destructive_query(query, self.destructive_warning) is False + ): message = "Wise choice. Command execution stopped." return [(None, None, None, message)] @@ -644,8 +650,10 @@ class PGCli: query = MetaQuery(query=text, successful=False) try: - if self.destructive_warning: - destroy = confirm = confirm_destructive_query(text) + if self.destructive_warning != "off": + destroy = confirm = confirm_destructive_query( + text, self.destructive_warning + ) if destroy is False: click.secho("Wise choice!") raise KeyboardInterrupt @@ -1188,7 +1196,10 @@ class PGCli: help="Automatically switch to vertical output mode if the result is wider than the terminal width.", ) @click.option( - "--warn/--no-warn", default=None, help="Warn before running a destructive query." + "--warn", + default=None, + type=click.Choice(["all", "moderate", "off"]), + help="Warn before running a destructive query.", ) @click.argument("dbname", default=lambda: None, envvar="PGDATABASE", nargs=1) @click.argument("username", default=lambda: None, envvar="PGUSER", nargs=1) |