Honor --no-headers for --fmt and --table output (#566) (#751)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Johnson K C 2026-07-06 09:54:17 -07:00 committed by GitHub
commit d516e58543
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 67 additions and 11 deletions

View file

@ -111,7 +111,11 @@ def output_options(fn):
),
click.option("--csv", is_flag=True, help="Output CSV"),
click.option("--tsv", is_flag=True, help="Output TSV"),
click.option("--no-headers", is_flag=True, help="Omit CSV headers"),
click.option(
"--no-headers",
is_flag=True,
help="Omit headers from CSV/TSV and table/--fmt output",
),
click.option(
"-t", "--table", is_flag=True, help="Output as a formatted table"
),
@ -240,7 +244,13 @@ def tables(
yield row
if table or fmt:
print(tabulate.tabulate(_iter(), headers=headers, tablefmt=fmt or "simple"))
print(
tabulate.tabulate(
_iter(),
headers=() if no_headers else 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:
@ -2145,7 +2155,9 @@ def _execute_query(
elif fmt or table:
print(
tabulate.tabulate(
list(cursor), headers=headers, tablefmt=fmt or "simple"
list(cursor),
headers=() if no_headers else headers,
tablefmt=fmt or "simple",
)
)
elif csv or tsv: