✨ feat(cli): add --args flag and ARGS dict for jq-compatible argument passing#1768
Merged
Conversation
… passing
Add --data flag that provides positional string arguments accessible as
ARGS."positional" in queries, and update --args to also populate ARGS."named".
When either --args or --data is given, ARGS = {"positional": [...], "named": {...}}.
- Add --data flag (jq's --args equivalent) with allow_hyphen_values support
- ARGS dict is only defined when --args or --data is provided
- --args NAME VALUE continues to define individual named variables as before
- Add define_value() to Engine and Evaluator for injecting arbitrary RuntimeValues
- Update CLI help text with consistent # comment style and ARGS usage examples
- Add comprehensive tests for all ARGS patterns and file/data separation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds jq-style argument passing support to the mq CLI by introducing a positional --argv flag and exposing both positional and named args to queries via an ARGS dict, backed by a new Engine::define_value API in mq-lang.
Changes:
- Add
--argv(positional string args) and defineARGS = {"positional": [...], "named": {...}}when--argsand/or--argvis used. - Extend
mq-lang’s API withdefine_valueto inject non-string runtime values into the evaluator environment. - Add unit tests in
mq-runcoveringARGSshape/access and ensuring files aren’t mixed with argv.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| crates/mq-run/src/cli.rs | Adds --argv, defines ARGS in the engine environment, updates CLI help, and introduces tests for ARGS behavior. |
| crates/mq-lang/src/eval.rs | Adds Evaluator::define_value to support injecting arbitrary runtime values. |
| crates/mq-lang/src/engine.rs | Exposes Engine::define_value as a public API wrapper around the evaluator. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Add `num_args = 2` to the `--args` and `--rawfile` clap argument definitions so that each invocation requires exactly a NAME VALUE pair. This prevents a potential index-out-of-bounds panic when an odd number of values was supplied and `chunks(2)` produced a chunk with only one element. Also add a regression test confirming a valid NAME VALUE pair succeeds.
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.
No description provided.