feat(jq): add --arg and --argjson flags#162
Open
pawaca wants to merge 3 commits intovercel-labs:mainfrom
Open
Conversation
|
@pawaca is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
Looks great. Please fix lint! |
Implement the two most commonly used jq variable-passing flags: - `--arg name value` binds $name as a string - `--argjson name json` binds $name as a parsed JSON value These leverage the existing variable binding infrastructure in the query engine (EvalContext.vars / withVar). The implementation adds an `initialVars` field to EvaluateOptions that pre-populates the evaluation context before filter execution. Includes 13 new tests covering: string binding, select filtering, multiple args, type correctness (--arg always string), JSON types (number/object/array/boolean), error handling, and combined usage.
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1317797 to
1de5e72
Compare
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
Adds the two most commonly used jq variable-passing flags:
--arg name value— binds$nameas a string value--argjson name json— binds$nameas a parsed JSON valueThese are essential for parameterized jq filters in shell scripts, e.g.:
Implementation
Leverages the existing variable binding infrastructure in the query engine (
EvalContext.vars/withVar):initialVars?: Map<string, QueryValue>toEvaluateOptions, used to pre-populateEvalContext.varsincreateContext()--arg/--argjsonflags during argument processing, collect intoinitialVarsmap, pass to evaluate optionsTotal change: ~30 lines of implementation + ~120 lines of tests.
Tests
13 new test cases covering:
--arg: string binding, select filtering, multiple args, type correctness (always string)--argjson: number, object, array, boolean binding--arg+--argjsonusage