Skip to content

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

Open
JOhnsonKC201 wants to merge 1 commit into
simonw:mainfrom
JOhnsonKC201:fix/no-headers-fmt-566
Open

Honor --no-headers for --fmt and --table output (#566)#751
JOhnsonKC201 wants to merge 1 commit into
simonw:mainfrom
JOhnsonKC201:fix/no-headers-fmt-566

Conversation

@JOhnsonKC201

@JOhnsonKC201 JOhnsonKC201 commented Jun 8, 2026

Copy link
Copy Markdown

Refs #566.

Problem

--no-headers was only honored for --csv/--tsv output. For the tabulate formats (--fmt ... and -t/--table) the flag was silently ignored, so the column-name header row was always printed:

$ sqlite-utils query library.db 'select asin from audible' --fmt plain --no-headers
asin        # <- should not be here
0062804006
0062891421

The two tabulate.tabulate(...) call sites (the query/memory output and the rows/tables output) always passed headers=headers regardless of the flag.

Fix

Both call sites now pass headers=() if no_headers else headers. tabulate renders headerless output cleanly for every format (plain, simple, github, grid, rst, …), so --no-headers now works consistently across CSV, TSV and all --fmt/--table formats. Default output (headers shown) is unchanged, and the CSV/TSV path is untouched.

$ sqlite-utils query library.db 'select asin from audible' --fmt plain --no-headers
0062804006
0062891421

I went with making the flag do what its name says (rather than raising an error on --fmt + --no-headers) because tabulate supports headerless rendering for all formats and this matches the documented purpose of the flag — and the use case in the issue (piping a single column into xargs/unix tools) is a legitimate one.

The --no-headers help text previously said "Omit CSV headers"; it now reads "Omit headers from CSV/TSV and table/--fmt output", and docs/cli-reference.rst is regenerated via cog to match.

Tests

Added test_output_table_no_headers, parametrized over --fmt simple, -t and --fmt github, asserting the header row is omitted (and the data preserved) for both the query and rows commands.

  • Full suite: 1042 passed, 17 skipped locally.
  • black . --check, cog --check README.md docs/*.rst and codespell all pass.

📚 Documentation preview 📚: https://sqlite-utils--751.org.readthedocs.build/en/751/

`--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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant