mirror of https://github.com/dbcli/pgcli
* Added \echo & \qecho for Issue #1335 * black + changelog updates * trying to re-kick build process
This commit is contained in:
parent
a615333686
commit
43360b5d1b
|
@ -1,3 +1,4 @@
|
|||
========
|
||||
Upcoming
|
||||
========
|
||||
|
||||
|
@ -17,6 +18,7 @@ Features:
|
|||
it will now not restart.
|
||||
* Config option to always run with a single connection.
|
||||
* Add comment explaining default LESS environment variable behavior and change example pager setting.
|
||||
* Added \echo & \qecho special commands. ([issue 1335](https://github.com/dbcli/pgcli/issues/1335)).
|
||||
|
||||
Bug fixes:
|
||||
----------
|
||||
|
|
|
@ -363,6 +363,23 @@ class PGCli:
|
|||
"Change the table format used to output results",
|
||||
)
|
||||
|
||||
self.pgspecial.register(
|
||||
self.echo,
|
||||
"\\echo",
|
||||
"\\echo [string]",
|
||||
"Echo a string to stdout",
|
||||
)
|
||||
|
||||
self.pgspecial.register(
|
||||
self.echo,
|
||||
"\\qecho",
|
||||
"\\qecho [string]",
|
||||
"Echo a string to the query output channel.",
|
||||
)
|
||||
|
||||
def echo(self, pattern, **_):
|
||||
return [(None, None, None, pattern)]
|
||||
|
||||
def change_table_format(self, pattern, **_):
|
||||
try:
|
||||
if pattern not in TabularOutputFormatter().supported_formats:
|
||||
|
@ -756,7 +773,9 @@ class PGCli:
|
|||
click.secho(str(e), err=True, fg="red")
|
||||
else:
|
||||
try:
|
||||
if self.output_file and not text.startswith(("\\o ", "\\? ")):
|
||||
if self.output_file and not text.startswith(
|
||||
("\\o ", "\\? ", "\\echo ")
|
||||
):
|
||||
try:
|
||||
with open(self.output_file, "a", encoding="utf-8") as f:
|
||||
click.echo(text, file=f)
|
||||
|
|
|
@ -296,6 +296,22 @@ def test_i_works(tmpdir, executor):
|
|||
run(executor, statement, pgspecial=cli.pgspecial)
|
||||
|
||||
|
||||
@dbtest
|
||||
def test_echo_works(executor):
|
||||
cli = PGCli(pgexecute=executor)
|
||||
statement = r"\echo asdf"
|
||||
result = run(executor, statement, pgspecial=cli.pgspecial)
|
||||
assert result == ["asdf"]
|
||||
|
||||
|
||||
@dbtest
|
||||
def test_qecho_works(executor):
|
||||
cli = PGCli(pgexecute=executor)
|
||||
statement = r"\qecho asdf"
|
||||
result = run(executor, statement, pgspecial=cli.pgspecial)
|
||||
assert result == ["asdf"]
|
||||
|
||||
|
||||
@dbtest
|
||||
def test_watch_works(executor):
|
||||
cli = PGCli(pgexecute=executor)
|
||||
|
|
Loading…
Reference in New Issue