summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Roten <tsr@lavabit.com>2017-06-11 20:10:59 -0500
committerThomas Roten <tsr@lavabit.com>2017-06-11 20:10:59 -0500
commitee0e9a6f34a14f5c5ebb42b8ae0c5092a1103e14 (patch)
tree351ed522d4a9d1d6fc219482e9d28978f10b1a28
parent1e421936472833903772ae6def06f6cc34d64b23 (diff)
parentbbb5717a0352fb6d489b41ae8b40509fd26221ed (diff)
Merge branch 'master' of github.com:dbcli/mycli into feature/style_output
* 'master' of github.com:dbcli/mycli: remove \r\n from expect_exact, atprompt False for tee Don't use expect_pager for status lines. Add echo status text to changelog. PEP 8 fix. Do not output status text through pager or output files.
-rw-r--r--changelog.md1
-rwxr-xr-xmycli/main.py46
-rw-r--r--test/features/steps/crud_database.py10
-rw-r--r--test/features/steps/crud_table.py12
-rw-r--r--test/features/steps/iocommands.py5
-rw-r--r--test/features/steps/named_queries.py4
-rw-r--r--test/features/steps/specials.py6
7 files changed, 42 insertions, 42 deletions
diff --git a/changelog.md b/changelog.md
index 3973669..97a1943 100644
--- a/changelog.md
+++ b/changelog.md
@@ -11,6 +11,7 @@ Features:
* Add special command to show create table statement. (Thanks: [Ryan Smith])
* Display all result sets returned by stored procedures (Thanks: [Thomas Roten]).
* Add current time to prompt options (Thanks: [Thomas Roten]).
+* Output status text in a more intuitive way (Thanks: [Thomas Roten]).
* Add colored/styled headers and odd/even rows (Thanks: [Thomas Roten]).
Bug Fixes:
diff --git a/mycli/main.py b/mycli/main.py
index 23ab940..3893046 100755
--- a/mycli/main.py
+++ b/mycli/main.py
@@ -530,15 +530,18 @@ class MyCli(object):
else:
max_width = None
- formatted = self.format_output(title, cur, headers, status,
- special.is_expanded_output(),
- max_width)
+ formatted = self.format_output(
+ title, cur, headers, special.is_expanded_output(),
+ max_width)
t = time() - start
try:
if result_count > 0:
self.echo('')
- self.output('\n'.join(formatted))
+ try:
+ self.output('\n'.join(formatted), status)
+ except KeyboardInterrupt:
+ pass
if special.is_timing_enabled():
self.echo('Time: %0.03fs' % t)
except KeyboardInterrupt:
@@ -663,13 +666,15 @@ class MyCli(object):
self.log_output(s)
click.secho(s, **kwargs)
- def output_fits_on_screen(self, output):
+ def output_fits_on_screen(self, output, status=None):
"""Check if the given output fits on the screen."""
size = self.cli.output.get_size()
margin = self.get_reserved_space() + self.get_prompt(self.prompt_format).count('\n') + 1
if special.is_timing_enabled():
margin += 1
+ if status:
+ margin += 1 + status.count('\n')
for i, line in enumerate(output.splitlines(), 1):
if len(line) > size.columns or i > (size.rows - margin):
@@ -677,22 +682,30 @@ class MyCli(object):
return True
- def output(self, output):
+ def output(self, output, status=None):
"""Output text to stdout or a pager command.
+ The status text is not outputted to pager or files.
+
The message will be logged in the audit log, if enabled. The
message will be written to the tee file, if enabled. The
message will be written to the output file, if enabled.
"""
- self.log_output(output)
- special.write_tee(output)
- special.write_once(output)
+ if output:
+ self.log_output(output)
+ special.write_tee(output)
+ special.write_once(output)
+
+ if (self.explicit_pager or
+ (special.is_pager_enabled() and not self.output_fits_on_screen(output, status))):
+ click.echo_via_pager(output)
+ else:
+ click.secho(output)
- if self.explicit_pager or (special.is_pager_enabled() and not self.output_fits_on_screen(output)):
- click.echo_via_pager(output)
- else:
- click.secho(output)
+ if status:
+ self.log_output(status)
+ click.secho(status)
def configure_pager(self):
# Provide sane defaults for less if they are empty.
@@ -769,11 +782,11 @@ class MyCli(object):
results = self.sqlexecute.run(query)
for result in results:
title, cur, headers, status = result
- output = self.format_output(title, cur, headers, None)
+ output = self.format_output(title, cur, headers)
for line in output:
click.echo(line, nl=new_line)
- def format_output(self, title, cur, headers, status, expanded=False,
+ def format_output(self, title, cur, headers, expanded=False,
max_width=None):
expanded = expanded or self.formatter.format_name == 'vertical'
output = []
@@ -795,9 +808,6 @@ class MyCli(object):
output.append(formatted)
- if status: # Only print the status if it's not None.
- output.append(status)
-
return output
def get_reserved_space(self):
diff --git a/test/features/steps/crud_database.py b/test/features/steps/crud_database.py
index af8580e..c99bd8e 100644
--- a/test/features/steps/crud_database.py
+++ b/test/features/steps/crud_database.py
@@ -76,24 +76,20 @@ def step_see_help(context):
@then('we see database created')
def step_see_db_created(context):
"""Wait to see create database output."""
- wrappers.expect_pager(context, 'Query OK, 1 row affected\r\n', timeout=2)
+ wrappers.expect_exact(context, 'Query OK, 1 row affected', timeout=2)
@then('we see database dropped')
def step_see_db_dropped(context):
"""Wait to see drop database output."""
- wrappers.expect_pager(context, 'Query OK, 0 rows affected\r\n', timeout=2)
+ wrappers.expect_exact(context, 'Query OK, 0 rows affected', timeout=2)
@then('we see database connected')
def step_see_db_connected(context):
"""Wait to see drop database output."""
wrappers.expect_exact(
- context, context.conf['pager_boundary'] + '\r\n', timeout=5)
- wrappers.expect_exact(
context, 'You are now connected to database "', timeout=2)
wrappers.expect_exact(context, '"', timeout=2)
- wrappers.expect_exact(context, ' as user "{0}"\r\n'.format(
+ wrappers.expect_exact(context, ' as user "{0}"'.format(
context.conf['user']), timeout=2)
- wrappers.expect_exact(
- context, context.conf['pager_boundary'] + '\r\n', timeout=5)
diff --git a/test/features/steps/crud_table.py b/test/features/steps/crud_table.py
index f6e9f04..c9d2a55 100644
--- a/test/features/steps/crud_table.py
+++ b/test/features/steps/crud_table.py
@@ -57,19 +57,19 @@ def step_drop_table(context):
@then('we see table created')
def step_see_table_created(context):
"""Wait to see create table output."""
- wrappers.expect_pager(context, 'Query OK, 0 rows affected\r\n', timeout=2)
+ wrappers.expect_exact(context, 'Query OK, 0 rows affected', timeout=2)
@then('we see record inserted')
def step_see_record_inserted(context):
"""Wait to see insert output."""
- wrappers.expect_pager(context, 'Query OK, 1 row affected\r\n', timeout=2)
+ wrappers.expect_exact(context, 'Query OK, 1 row affected', timeout=2)
@then('we see record updated')
def step_see_record_updated(context):
"""Wait to see update output."""
- wrappers.expect_pager(context, 'Query OK, 1 row affected\r\n', timeout=2)
+ wrappers.expect_exact(context, 'Query OK, 1 row affected', timeout=2)
@then('we see data selected')
@@ -82,17 +82,17 @@ def step_see_data_selected(context):
+-----+\r
| yyy |\r
+-----+\r
- 1 row in set\r
"""), timeout=1)
+ wrappers.expect_exact(context, '1 row in set', timeout=2)
@then('we see record deleted')
def step_see_data_deleted(context):
"""Wait to see delete output."""
- wrappers.expect_pager(context, 'Query OK, 1 row affected\r\n', timeout=2)
+ wrappers.expect_exact(context, 'Query OK, 1 row affected', timeout=2)
@then('we see table dropped')
def step_see_table_dropped(context):
"""Wait to see drop output."""
- wrappers.expect_pager(context, 'Query OK, 0 rows affected\r\n', timeout=2)
+ wrappers.expect_exact(context, 'Query OK, 0 rows affected', timeout=2)
diff --git a/test/features/steps/iocommands.py b/test/features/steps/iocommands.py
index 6fe36f4..27b5529 100644
--- a/test/features/steps/iocommands.py
+++ b/test/features/steps/iocommands.py
@@ -54,7 +54,6 @@ def step_tee_ouptut(context):
os.remove(context.tee_file_name)
context.cli.sendline('tee {0}'.format(
os.path.basename(context.tee_file_name)))
- wrappers.expect_pager(context, "\r\n", timeout=5)
@when(u'we query "select 123456"')
@@ -66,14 +65,13 @@ def step_query_select_123456(context):
+--------+\r
| 123456 |\r
+--------+\r
- 1 row in set\r
"""), timeout=5)
+ wrappers.expect_exact(context, '1 row in set', timeout=2)
@when(u'we notee output')
def step_notee_output(context):
context.cli.sendline('notee')
- wrappers.expect_pager(context, "\r\n", timeout=5)
@then(u'we see 123456 in tee output')
@@ -82,4 +80,3 @@ def step_see_123456_in_ouput(context):
assert '123456' in f.read()
if os.path.exists(context.tee_file_name):
os.remove(context.tee_file_name)
- context.atprompt = True
diff --git a/test/features/steps/named_queries.py b/test/features/steps/named_queries.py
index 40bf5bc..60115c5 100644
--- a/test/features/steps/named_queries.py
+++ b/test/features/steps/named_queries.py
@@ -32,7 +32,7 @@ def step_delete_named_query(context):
@then('we see the named query saved')
def step_see_named_query_saved(context):
"""Wait to see query saved."""
- wrappers.expect_pager(context, 'Saved.\r\n', timeout=1)
+ wrappers.expect_exact(context, 'Saved.', timeout=1)
@then('we see the named query executed')
@@ -45,4 +45,4 @@ def step_see_named_query_executed(context):
@then('we see the named query deleted')
def step_see_named_query_deleted(context):
"""Wait to see query deleted."""
- wrappers.expect_pager(context, 'foo: Deleted\r\n', timeout=1)
+ wrappers.expect_exact(context, 'foo: Deleted', timeout=1)
diff --git a/test/features/steps/specials.py b/test/features/steps/specials.py
index f7715b9..14a87cc 100644
--- a/test/features/steps/specials.py
+++ b/test/features/steps/specials.py
@@ -21,8 +21,4 @@ def step_refresh_completions(context):
def step_see_refresh_started(context):
"""Wait to see refresh output."""
wrappers.expect_exact(
- context, context.conf['pager_boundary'] + '\r\n', timeout=5)
- wrappers.expect_exact(
- context, 'Auto-completion refresh started in the background.\r\n', timeout=2)
- wrappers.expect_exact(
- context, context.conf['pager_boundary'] + '\r\n', timeout=5)
+ context, 'Auto-completion refresh started in the background.', timeout=2)