Skip to content

✨ feat(cli): add --args flag and ARGS dict for jq-compatible argument passing#1768

Merged
harehare merged 5 commits into
mainfrom
feat/args-data-flag
May 20, 2026
Merged

✨ feat(cli): add --args flag and ARGS dict for jq-compatible argument passing#1768
harehare merged 5 commits into
mainfrom
feat/args-data-flag

Conversation

@harehare
Copy link
Copy Markdown
Owner

No description provided.

harehare added 2 commits May 20, 2026 22:06
… 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
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 20, 2026

Merging this PR will not alter performance

✅ 29 untouched benchmarks


Comparing feat/args-data-flag (3cbec75) with main (f1334bf)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (75e8c5e) during the generation of this report, so f1334bf was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 define ARGS = {"positional": [...], "named": {...}} when --args and/or --argv is used.
  • Extend mq-lang’s API with define_value to inject non-string runtime values into the evaluator environment.
  • Add unit tests in mq-run covering ARGS shape/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.

Comment thread crates/mq-run/src/cli.rs Outdated
Comment thread crates/mq-run/src/cli.rs Outdated
Comment thread crates/mq-run/src/cli.rs
Comment thread crates/mq-run/src/cli.rs
Comment thread crates/mq-run/src/cli.rs
harehare and others added 3 commits May 20, 2026 22:19
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.
@harehare harehare merged commit 4cfa7f3 into main May 20, 2026
10 checks passed
@harehare harehare deleted the feat/args-data-flag branch May 20, 2026 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants