Skip to content

Commit fc3bfe7

Browse files
committed
CLI: Add support for max_rows, display all columns wraparound
Signed-off-by: Dinesh Dutt <[email protected]>
1 parent d618058 commit fc3bfe7

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

suzieq/cli/sqcmds/command.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ def _pager_print(self, df: pd.DataFrame) -> None:
274274
else:
275275
print(df)
276276

277+
# pylint: disable=too-many-statements
277278
def _gen_output(self, df: pd.DataFrame, json_orient: str = "records",
278279
dont_strip_cols: bool = False, sort: bool = True):
279280

@@ -291,6 +292,9 @@ def _gen_output(self, df: pd.DataFrame, json_orient: str = "records",
291292
cols = df.columns.tolist()
292293
is_error = False
293294

295+
max_rows = self.ctxt.max_rows
296+
all_columns = self.ctxt.all_columns
297+
294298
if dont_strip_cols or not all(item in df.columns for item in cols):
295299
cols = df.columns.tolist()
296300

@@ -317,9 +321,11 @@ def _gen_output(self, df: pd.DataFrame, json_orient: str = "records",
317321
'timestamp' not in self.columns and not dont_strip_cols and
318322
'timestamp' in df.columns and 'timestamp' in cols):
319323
cols.remove('timestamp')
320-
with pd.option_context('precision', 3,
321-
'display.max_colwidth', max_colwidth,
322-
'display.max_rows', 256):
324+
with pd.option_context(
325+
'precision', 3,
326+
'display.max_colwidth', max_colwidth,
327+
'display.max_rows', max_rows,
328+
'display.expand_frame_repr', not all_columns):
323329
df = self.sqobj.humanize_fields(df)
324330
if df.empty:
325331
print(df)

suzieq/cli/sqcmds/context_commands.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
@argument("pager", description="Enable pagination prompt on longer outputs",
2323
choices=['on', 'off'])
2424
@argument('col_width', description='Max Width of each column in table display')
25+
@argument('max_rows',
26+
description='Max rows to display before ellipsis is shown')
27+
@argument('all_columns',
28+
description='Display all columns wrapping around if necessary',
29+
choices=['yes', 'no'])
2530
@argument(
2631
"engine",
2732
choices=SUPPORTED_ENGINES,
@@ -57,6 +62,8 @@ def set_ctxt(
5762
datadir: str = "",
5863
debug: str = '',
5964
col_width: int = 50,
65+
max_rows: int = None,
66+
all_columns: str = None,
6067
rest_server_ip: str = "",
6168
rest_server_port: str = "",
6269
rest_api_key: str = "",
@@ -93,6 +100,15 @@ def set_ctxt(
93100
if col_width:
94101
ctxt.col_width = int(col_width)
95102

103+
if max_rows is not None:
104+
if max_rows == 0:
105+
ctxt.max_rows = None
106+
else:
107+
ctxt.max_rows = max_rows
108+
109+
if all_columns is not None:
110+
ctxt.all_columns = all_columns == "yes"
111+
96112
if pager == 'on':
97113
ctxt.pager = True
98114
elif pager == 'off':

suzieq/shared/context.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class SqContext:
1818
exec_time: str = ''
1919
engine: str = None
2020
col_width: int = 50
21+
max_rows: int = 256
22+
all_columns: bool = False
2123
debug: bool = False
2224
sort_fields: List[str] = field(default_factory=list)
2325
view: str = None

0 commit comments

Comments
 (0)