Skip to content

Add --output <file> flag to write results to a file #87

@vmvarela

Description

@vmvarela

Description

sql-pipe currently writes results only to stdout. In automation scripts or when building pipelines with multiple steps, users often want to write results directly to a file without shell redirection. A --output flag makes the intent explicit and avoids accidental overwrites common with >.

Example

# Without --output (works but fragile in scripts)
sql-pipe 'SELECT * FROM t' < input.csv > results.csv

# With --output (explicit, safer)
cat input.csv | sql-pipe --output results.csv 'SELECT * FROM t'

# Combining with --json
cat input.csv | sql-pipe --json --output report.json 'SELECT region, SUM(revenue) FROM t GROUP BY region'

Acceptance Criteria

  • --output <path> writes stdout to the given file path, creating or overwriting it
  • If the file cannot be created (bad path, permissions), exit with code 1 and a clear error message
  • Without --output, behaviour is unchanged (write to stdout)
  • Compatible with all output modes: CSV (default), --json, --header
  • Documented in --help, README.md Flags table, and docs/sql-pipe.1.scd
  • Test: output written to file, file contains correct content, missing parent directory error handled

Notes

  • Implementation: open file before query execution, pass writer to execQuery
  • Atomic write (write to temp file, rename) is a nice-to-have but not required for v1

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:mediumShould be done soonsize:xsTrivial — less than 1 hourstatus:readyRefined and ready for sprint selectiontype:featureNew functionality

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions