Skip to content

Feature: infer output format from --output file extension #222

Description

@vmvarela

Context

--output result.json still writes CSV unless -O json is also passed. Input files already auto-detect format by extension (data.parquet, data.yaml — no -I needed); output should behave symmetrically.

Proposed behavior

sql-pipe data.csv -O json --output result.json 'SELECT * FROM t'   # today: both flags required
sql-pipe data.csv --output result.json 'SELECT * FROM t'           # proposed: .json implies -O json
  • When --output <file> is set and -O/--output-format is not, infer the format from the extension: .csv .tsv .json .ndjson .xml .md .html .sql.
  • Explicit -O always wins over the extension.
  • Unknown or missing extension → current default (csv), no error.

Excluded (YAGNI)

  • Inferring format for stdout (no filename — keep csv default)
  • Warning when extension and -O disagree (explicit flag wins, silently)

Acceptance criteria

  • --output r.json writes JSON without -O
  • -O tsv --output r.json writes TSV (flag wins)
  • --output r.txt falls back to csv
  • Same mapping table reused from input extension detection if practical
  • Help text for --output mentions the inference
  • Integration test

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:lowNice to have, do when possiblesize:xsTrivial — less than 1 hourtype:featureNew functionality

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions