Honor --no-headers for --fmt and --table output (#566)#751
Open
JOhnsonKC201 wants to merge 1 commit into
Open
Conversation
`--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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #566.
Problem
--no-headerswas only honored for--csv/--tsvoutput. For the tabulate formats (--fmt ...and-t/--table) the flag was silently ignored, so the column-name header row was always printed:The two
tabulate.tabulate(...)call sites (thequery/memoryoutput and therows/tablesoutput) always passedheaders=headersregardless of the flag.Fix
Both call sites now pass
headers=() if no_headers else headers.tabulaterenders headerless output cleanly for every format (plain,simple,github,grid,rst, …), so--no-headersnow works consistently across CSV, TSV and all--fmt/--tableformats. Default output (headers shown) is unchanged, and the CSV/TSV path is untouched.I went with making the flag do what its name says (rather than raising an error on
--fmt+--no-headers) becausetabulatesupports 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 intoxargs/unix tools) is a legitimate one.The
--no-headershelp text previously said "Omit CSV headers"; it now reads "Omit headers from CSV/TSV and table/--fmt output", anddocs/cli-reference.rstis regenerated via cog to match.Tests
Added
test_output_table_no_headers, parametrized over--fmt simple,-tand--fmt github, asserting the header row is omitted (and the data preserved) for both thequeryandrowscommands.black . --check,cog --check README.md docs/*.rstandcodespellall pass.📚 Documentation preview 📚: https://sqlite-utils--751.org.readthedocs.build/en/751/