cli: honor --no-headers for table and tabulate-style formats

--no-headers was already wired up for csv/tsv output but the
tabulate.tabulate calls (used for --table and --fmt) passed headers
unconditionally, so the header row still printed. Pass () to tabulate
in that case to suppress it.

Closes #566

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
This commit is contained in:
Charlie Tonneslan 2026-05-18 08:10:30 -04:00
commit 3c00175d82

View file

@ -236,7 +236,8 @@ def tables(
yield row
if table or fmt:
print(tabulate.tabulate(_iter(), headers=headers, tablefmt=fmt or "simple"))
tab_headers = () if no_headers else headers
print(tabulate.tabulate(_iter(), headers=tab_headers, tablefmt=fmt or "simple"))
elif csv or tsv:
writer = csv_std.writer(sys.stdout, dialect="excel-tab" if tsv else "excel")
if not no_headers:
@ -2137,9 +2138,10 @@ def _execute_query(
else:
sys.stdout.write(str(data) + "\n")
elif fmt or table:
tab_headers = () if no_headers else headers
print(
tabulate.tabulate(
list(cursor), headers=headers, tablefmt=fmt or "simple"
list(cursor), headers=tab_headers, tablefmt=fmt or "simple"
)
)
elif csv or tsv: