Skip to content

feat: add --exit-status / -e flag (exit code 1 for false/null/empty output) - #1823

Merged
harehare merged 4 commits into
harehare:mainfrom
sridhar-3009:feat/exit-status-flag
Jun 21, 2026
Merged

harehare merged 4 commits into
harehare:mainfrom
sridhar-3009:feat/exit-status-flag

Conversation

@sridhar-3009

Copy link
Copy Markdown
Contributor

Summary

Closes #1799.

Adds -e / --exit-status to mq, mirroring jq's --exit-status behaviour:

Output Exit code
At least one truthy value 0
Only false or null values 1
No output 1

Everything else — empty string "", 0, [], {} — is truthy and exits 0.

Usage

# Exits 1 — heading not found
mq -e 'select(.type == "heading" and .depth == 99)' doc.md

# Exits 0 — found something
mq -e 'select(.type == "heading")' doc.md

# Useful in shell scripts
if mq -e 'select(.type == "code")' README.md > /dev/null; then
  echo "has code blocks"
fi

Implementation

  • OutputArgs.exit_status: bool — new clap flag (-e / --exit-status)
  • is_falsy() helper — matches RuntimeValue::None | Boolean(false)
  • thread_local! { HAD_TRUTHY_OUTPUT } — tracks across print() calls without refactoring the streaming output architecture
  • After process_batch / process_streaming, calls std::process::exit(1) when the flag is set and no truthy value was seen

…ty output

Mirrors jq's --exit-status behaviour:

- exit 1 if the output contains only false/null values
- exit 1 if no output was produced
- exit 0 for any other output (including empty string, 0, [], {})

Implementation:
- Add OutputArgs.exit_status: bool (-e / --exit-status)
- Add is_falsy() helper (matches RuntimeValue::None | Boolean(false))
- Use thread_local! HAD_TRUTHY_OUTPUT to track across print() calls
  without requiring a large refactor of the streaming output architecture
- After process_batch/streaming, call std::process::exit(1) if
  exit_status is set and no truthy value was seen

Closes #1799
@harehare

harehare commented Jun 5, 2026 •

Copy link
Copy Markdown
Owner

@sridhar-3009
Thanks for the PR!

It looks like some tests are failing in CI. Could you take a look when you get a chance?

Let me know if you need any help!

harehare added 3 commits June 21, 2026 18:55
print() was reassigning runtime_values to the original RuntimeValues
type instead of the .values() slice, breaking the build. The truthy
flag also used a thread_local, which never propagates from rayon
worker threads back to the main thread once batch processing goes
parallel (>10 files). And is_falsy() only checked None/Boolean(false),
missing the most common case: select() with no match, which replaces
non-matching nodes with an empty value instead of dropping them.

Switch HAD_TRUTHY_OUTPUT to an AtomicBool, fix the type mismatch in
print(), and treat empty values as falsy. Add tests covering all three.
Merging main into this branch silently dropped the trailing Ok(())
in test_exit_status_parallel_batch and the #[rstest] attribute above
test_completion's cases, breaking the build (E0308 / E0433 / "cannot
find attribute case"). Restore both.
@harehare

Copy link
Copy Markdown
Owner

I took a look and ironed out a few issues. Merging this in now, really appreciate the contribution!

@harehare
harehare merged commit 80d406a into harehare:main Jun 21, 2026
9 checks passed
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
mq 0.6.2

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## What's Changed

###  ✨ New Features

- Allow pipeline expressions as function arguments by @VrtxOmega in harehare/mq#1865
- ✨ feat(playground): add drag-and-drop file import to editors by @harehare in harehare/mq#1885
- ✨ feat(mq-web): expose clearHttpCache and clearAllHttpCache APIs by @harehare in harehare/mq#1890
- ✨ feat(mq-ffi): expose engine module/config APIs and mq_version by @harehare in harehare/mq#1893
- ✨ feat(mq-repl): add /save command test and fix missing match arm by @harehare in harehare/mq#1896
- ✨ feat(mq-lsp): add code actions and rename support by @harehare in harehare/mq#1900
- ✨ feat(mq-run): add shell completion subcommand  by @harehare in harehare/mq#1902
- ✨ feat(mq-lang): add set_children builtin function by @harehare in harehare/mq#1907
- ✨ feat(mq-lang): add md module for building markdown from scratch by @harehare in harehare/mq#1906
- ✨ feat(mq-lang): make md::doc accept variadic arguments by @harehare in harehare/mq#1909
- feat: add --exit-status / -e flag (exit code 1 for false/null/empty output) by @sridhar-3009 in harehare/mq#1823
- ✨ feat(mq-nodejs): add hover and HTTP cache control APIs by @harehare in harehare/mq#1910

###  🐛  Bug Fixes

- 🐛 fix(cst): support pipeline expressions as function arguments by @harehare in harehare/mq#1866
- 💄 fix(playground): replace alert() with showToast() for error messages by @harehare in harehare/mq#1877
- fix(mq-lang): handle "v"/"V" prefix in semver_parse by @aodihis in harehare/mq#1887
- 🐛 fix(mq-lang): escape embedded double-quotes in csv_stringify by @harehare in harehare/mq#1892
- 🐛 fix(mq-lang): block SSRF/DNS-rebinding in http-import resolver by @harehare in harehare/mq#1901
- 🐛 fix(mq-check): preserve generic arm type when union with concrete None arm by @harehare in harehare/mq#1904
- 🐛 fix(mq-formatter): fix indentation of wrapped def/fn params when inline by @harehare in harehare/mq#1908
- 🐛 fix(mq-wasm): gate OPFS-only helpers behind opfs feature by @harehare in harehare/mq#1911

### ♻ Refactor

- ♻ refactor(http-import): make HTTP fetcher pluggable via HttpFetcher trait by @harehare in harehare/mq#1886

###  📦 Build / Dependencies

- build(deps): bump the dependencies group with 2 updates by @dependabot[bot] in harehare/mq#1882
- build(deps): bump which from 8.0.2 to 8.0.3 in the dependencies group by @dependabot[bot] in harehare/mq#1881
- build(deps-dev): bump the dependencies group in /editors/vscode with 4 updates by @dependabot[bot] in harehare/mq#1878
- build(deps-dev): bump oxlint from 1.68.0 to 1.69.0 in /packages/mq-web in the dependencies group by @dependabot[bot] in harehare/mq#1879
- build(deps-dev): bump the dependencies group in /packages/mq-playground with 2 updates by @dependabot[bot] in harehare/mq#1880
- build(deps-dev): bump js-yaml from 4.1.1 to 4.2.0 in /editors/vscode by @dependabot[bot] in harehare/mq#1883
- build(deps): bump cbindgen from 0.29.3 to 0.29.4 in the dependencies group by @dependabot[bot] in harehare/mq#1888
- 📦 build(nix): update flake.lock to latest nixpkgs and rust-overlay by @harehare in harehare/mq#1889
- build(deps): bump taiki-e/install-action from 2.81.8 to 2.81.9 in the dependencies group by @dependabot[bot] in harehare/mq#1894
- build(deps-dev): bump @types/node from 25.9.2 to 25.9.3 in /editors/vscode in the dependencies group by @dependabot[bot] in harehare/mq#1898
- build(deps): bump the dependencies group with 2 updates by @dependabot[bot] in harehare/mq#1899
- build(deps): bump smallvec from 1.15.1 to 1.15.2 in the dependencies group by @dependabot[bot] in harehare/mq#1903

## New Contributors

* @VrtxOmega made their first contribution in harehare/mq#1865
* @aodihis made their first contribution in harehare/mq#1887
* @sridhar-3009 made their first contribution in harehare/mq#1823

**Full Changelog**: harehare/mq@v0.6.1...v0.6.2
</pre>
  <p>View the full release notes at <a href="https://github.com/harehare/mq/releases/tag/v0.6.2">https://github.com/harehare/mq/releases/tag/v0.6.2</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!12066
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.

Add -e / --exit-status flag to return exit code 1 for None/false/empty results

2 participants