Skip to content

fix: parse sample count in inspect mode - #261

Merged
vmvarela merged 1 commit into
masterfrom
fix/237-inspect-sample-count
Oct 14, 2026
Merged

vmvarela merged 1 commit into
masterfrom
fix/237-inspect-sample-count

Conversation

@vmvarela

Copy link
Copy Markdown
Owner

Summary

--inspect sample N and --inspect=sample N treated the count N as a positional
input filename, so e.g. sql-pipe --inspect sample 2 failed with cannot open file '2'
(exit 2) instead of printing the schema plus 2 rows.

The parser now consumes an immediately following positive integer as the sample count
for both canonical --inspect syntaxes, using exactly the same rules the deprecated
--sample flag already used: flags and -- are not consumed, non-numeric names are
left as file arguments, and 0 is a usage error (stderr diagnostic sample count must be a positive integer (--inspect sample or --sample), exit 1). To sample a file whose
name is a number, use ./N or put it after --.

  • Regression tests added first in build.zig (9 new Bash integration tests); the five
    behavioral ones (--inspect sample 2, --inspect=sample 2, count-not-file with
    --no-stdin, zero-count usage error, missing-source diagnostic with count) failed
    against the unmodified source (exit 2 / default count) and pass after the fix.
  • Documentation updated only where the sample-count contract is described: CLI help
    (src/args.zig, example changed from --sample 5 to --inspect sample 5), README
    inspect section and --inspect table row, and the man page source
    (docs/sql-pipe.1.scd).
  • Deprecated --sample [n], --sample=n, the deprecation warning, and the exit-code
    contract (0/1/2/3) are unchanged.

Fixes #237

Validation

  • zig build -Dbundle-sqlite=true -Doptimize=ReleaseSafe — pass
  • zig build unit-test -Dbundle-sqlite=true — pass
  • zig build test -Dbundle-sqlite=true — pass (all integration tests green;
    before the fix the 5 new regression tests failed as expected)
  • Manual: printf 'name,age\nAlice,30\nBob,25\nCarol,35\n' | ./zig-out/bin/sql-pipe --inspect sample 2
    prints schema on stderr and header + 2 rows on stdout, exit 0; --inspect=sample 2 same;
    --inspect sample 0 exits 1 with the new diagnostic
  • zig fmt --check on tracked *.zig files reports pre-existing violations on master
    (also flagged by CI lint setup); the files touched here are already nonconforming on
    master and none of the reported diffs intersect the new code

Note: GitHub CI does not run the Bash integration suite on Windows; Windows jobs only
compile and run unit tests, so the new CLI cases are verified on Linux/macOS only.

--inspect sample N and --inspect=sample N now consume an immediately following positive integer as the sample count, with the same rules as the deprecated --sample flag (flags, --, and non-numeric names are not consumed; zero is a usage error with exit 1). Previously the count was left as a positional argument and treated as an input file.

Clarify the positive-integer contract and the ./N / -- disambiguation in the CLI help, README, and man page.

Fixes #237
@github-actions github-actions Bot added the bug Something isn't working label Oct 14, 2026
@vmvarela
vmvarela merged commit 75eb994 into master Oct 14, 2026
5 checks passed
@vmvarela
vmvarela deleted the fix/237-inspect-sample-count branch October 14, 2026 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] --inspect sample <n> broken: count treated as filename

1 participant