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

`--no-headers` was only applied to `--csv`/`--tsv` output. For the tabulate
formats (`--fmt ...` and `-t`/`--table`) the flag was silently ignored, so
`sqlite-utils query db "select ..." --fmt plain --no-headers` still printed the
column-name header row.

Both `tabulate.tabulate(...)` call sites (the `query`/`memory` output and the
`rows`/`tables` output) now pass `headers=()` when `--no-headers` is set, which
suppresses the header row across every tabulate format while leaving the
default (headers shown) untouched. The CSV/TSV behaviour is unchanged.

Also clarifies the `--no-headers` help text, which previously said "Omit CSV
headers", and regenerates docs/cli-reference.rst via cog to match.

Adds test_output_table_no_headers covering --fmt simple, -t and --fmt github
for both the query and rows commands.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Johnson K C 2026-06-07 20:35:15 -04:00
commit de2601c42f
3 changed files with 67 additions and 11 deletions

View file

@ -107,7 +107,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"
),
@ -236,7 +240,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:
@ -2139,7 +2149,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: