fix(jq): fix argument parsing, add test coverage, update docs#221
Merged
fix(jq): fix argument parsing, add test coverage, update docs#221
Conversation
… --argjson
The jq builtin's argument parser had several issues:
- Combined short flags (e.g., -rn, -sc) were silently ignored because
the parser only matched exact single-flag strings like "-r" or "-n"
- --arg name value and --argjson name value were not handled, causing
the name argument to be misidentified as the jq filter and the actual
filter to be treated as a file argument ("Could not open file" errors)
- --indent N was not handled, causing N to be misidentified as the filter
- -- (end of options separator) was not supported
Fixes:
- Switch from iterator to index-based arg loop to consume multi-arg flags
- Parse combined short flags by iterating over characters (e.g., -rn -> -r + -n)
- Handle --arg/--argjson by consuming 2 extra args and passing variable
bindings to jaq Compiler::with_global_vars and Ctx::new
- Handle --indent N, --args, --jsonargs, and -- separator
- Skip unknown long flags gracefully
https://claude.ai/code/session_01JKnPuxK6nH19jUhfc2UVst
…docs - Unskip jq_try and jq_debug spec tests (both pass with jaq) - Add 8 new spec tests: empty input, NDJSON, multiple --arg, --argjson with objects, combined -snr flags, exit status for false/truthy - Add 10 new unit tests: invalid JSON, invalid filter, invalid argjson, empty/whitespace input, NDJSON, exit status, multiple bindings, combined flags - Update skip reasons to be precise about jaq limitations - Update 009-implementation-status: 108 tests (100 pass, 8 skip) - Update 005-builtins: document --arg, --argjson, -V, combined flags - Update compatibility.md: list all supported jq flags https://claude.ai/code/session_01JKnPuxK6nH19jUhfc2UVst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
-rn,-sc,-snr),--arg name value,--argjson name value,--indent N, and--separator now work correctlyTest plan
cargo fmt --checkpassescargo clippy --all-targets --all-features -- -D warningspassescargo test --all-featurespasses (all 37 jq unit tests, 100/108 spec tests pass, 8 skipped)