Skip to content

feat: add --header / -H flag for output column names#31

Merged
vmvarela merged 1 commit intomasterfrom
feature/10-header-option
Mar 3, 2026
Merged

feat: add --header / -H flag for output column names#31
vmvarela merged 1 commit intomasterfrom
feature/10-header-option

Conversation

@vmvarela
Copy link
Owner

@vmvarela vmvarela commented Mar 3, 2026

Summary

Add a --header (-H) flag that optionally prints column names as the first output row, improving usability when piping output to another sql-pipe invocation or saving as a named CSV.

Changes

src/main.zig

  • Added header: bool field to ParsedArgs
  • Added --header / -H flag parsing in parseArgs
  • Added writeField — RFC 4180 CSV field quoting (handles commas, quotes, newlines)
  • Added printHeaderRow — writes column names from sqlite3_column_name as the first CSV row
  • Modified execQuery to accept a header parameter and print the header before data rows
  • Updated help text to document the new option

docs/sql-pipe.1.scd

  • Added -H, --header option documentation
  • Added examples showing --header usage and round-trip piping

Acceptance Criteria

  • --header flag (or -H) prints column names as the first output row
  • Header off by default (preserves current streaming behaviour)
  • Header column names come from the SQLite column alias or original name
  • When --header is set, the output is valid CSV that can be piped back into sql-pipe

Testing

# Default (no header) — unchanged behaviour
echo 'name,age\nAlice,30\nBob,25' | sql-pipe 'SELECT * FROM t'
# Alice,30
# Bob,25

# With --header
echo 'name,age\nAlice,30\nBob,25' | sql-pipe --header 'SELECT * FROM t'
# name,age
# Alice,30
# Bob,25

# With -H and SQL alias
echo 'name,age\nAlice,30\nBob,25' | sql-pipe -H 'SELECT name AS "full name", age FROM t'
# full name,age
# Alice,30
# Bob,25

# Round-trip piping
echo 'name,age\nAlice,30\nBob,25' | sql-pipe -H 'SELECT * FROM t' | sql-pipe 'SELECT name FROM t'
# Alice
# Bob

Closes #10

Add a --header (-H) flag that prints column names as the first output
row. Column names come from sqlite3_column_name, which reflects SQL
aliases or original column names.

- Header off by default (preserves current streaming behaviour)
- Output is valid RFC 4180 CSV (fields with commas/quotes/newlines
  are properly quoted), enabling round-trip piping back into sql-pipe
- Updated help text and man page with option documentation and examples

Closes #10
@github-actions github-actions bot added the type:feature New functionality label Mar 3, 2026
@vmvarela vmvarela merged commit 81f05e5 into master Mar 3, 2026
6 checks passed
@vmvarela vmvarela deleted the feature/10-header-option branch March 3, 2026 18:23
@vmvarela vmvarela mentioned this pull request Mar 3, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:feature New functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Output header row option (--header / -H)

1 participant