Skip to content

fix(cli): honor --no-headers flag with --fmt/--table output#729

Open
CrepuscularIRIS wants to merge 1 commit intosimonw:mainfrom
CrepuscularIRIS:fix/no-headers-with-fmt
Open

fix(cli): honor --no-headers flag with --fmt/--table output#729
CrepuscularIRIS wants to merge 1 commit intosimonw:mainfrom
CrepuscularIRIS:fix/no-headers-with-fmt

Conversation

@CrepuscularIRIS
Copy link
Copy Markdown

@CrepuscularIRIS CrepuscularIRIS commented Apr 15, 2026

Summary

Fixes #566

The --no-headers flag was silently ignored when combined with --fmt or --table. Headers appeared in the output regardless.

Root Cause

The --no-headers flag was only checked in the CSV/TSV output branch (line 243). When --fmt or --table was used, tabulate.tabulate() was always called with headers=headers, bypassing the flag entirely. This affected both the tables command (line 240) and the query/_execute_query path (line 2148).

Changes

  • sqlite_utils/cli.py: Pass headers=() if no_headers else headers to both tabulate.tabulate() call sites. tabulate natively supports headers=() for suppressing header display.
  • tests/test_cli.py: Added test_output_table_no_headers (parametrized over plain and simple formats) and test_query_fmt_no_headers (verifies the query command path).

Testing

  • Full test suite passes (1039 passed, 16 skipped, 0 failures)
  • New tests fail when fix is reverted (verified)
  • No regressions from baseline (1036 → 1039 with 3 new tests)
python -m pytest tests/test_cli.py::test_output_table_no_headers tests/test_cli.py::test_query_fmt_no_headers -v

Notes

Chose to make --no-headers work with --fmt rather than raising an error, since tabulate supports headerless output cleanly via headers=(). This keeps --no-headers consistent across all output modes (CSV, TSV, and tabulate formats).


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

Fixes simonw#566

The --no-headers flag was only checked in the CSV/TSV output branch.
When --fmt or --table was used, tabulate.tabulate() was always called
with headers=headers, ignoring the flag. Pass headers=() instead when
no_headers is set, which suppresses header display while preserving
table formatting.
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.

--no-headers doesn't work on most formats

1 participant