Skip to content

fix(config): propagate --jq to nested pup calls via PUP_FILTER env#631

Merged
nogates merged 1 commit into
DataDog:mainfrom
jkirsteins:janis.kirsteins/jq-env-fallback
Jul 3, 2026
Merged

fix(config): propagate --jq to nested pup calls via PUP_FILTER env#631
nogates merged 1 commit into
DataDog:mainfrom
jkirsteins:janis.kirsteins/jq-env-fallback

Conversation

@jkirsteins

Copy link
Copy Markdown
Contributor

Problem

--jq is silently ignored when an extension delegates its HTTP call to a nested pup process, even though -o/--output works in the exact same chain. When an extension subcommand shells out through a helper to a nested pup api call, -o table propagates and takes effect but --jq does not:

pup --jq '.[] | {id: .id, service: .service_name, admin_teams: .admin_teams}' -o table test-extension list-items

Before this fix — the jq projection is dropped; every column comes back (data anonymized):

+------+--------+----------------------+----------------------+-------------------+-------------------+------------+---------------+--------+--------------+-------------------+-------------------+
| id   | name   | created_at           | updated_at           | created_by        | updated_by        | test_drive | route_id      | domain | service_name | service_namespace | server_group_name |
+==================================================================================================================================================================================================+
| 587  |        | 2026-04-20T20:16:35Z | 2026-04-20T20:16:35Z | agent@example.com | agent@example.com | false      | Rk3Lm9Qp2Xz=  | demo   | edge-backend | platform          | probe             |
|------+--------+----------------------+----------------------+-------------------+-------------------+------------+---------------+--------+--------------+-------------------+-------------------|
| 588  | sample | 2026-04-20T20:16:35Z | 2026-06-24T19:48:17Z | agent@example.com | agent@example.com | false      | 8Hn1Zu7BsfLa= | demo   | edge-backend | platform          | probe             |
|------+--------+----------------------+----------------------+-------------------+-------------------+------------+---------------+--------+--------------+-------------------+-------------------|
| 1104 |        | 2026-05-13T00:49:57Z | 2026-05-13T00:49:57Z | agent@example.com | agent@example.com | false      | eJ5yHpxLNCPc= | demo   | gateway      | commerce          | sandbox           |
|------+--------+----------------------+----------------------+-------------------+-------------------+------------+---------------+--------+--------------+-------------------+-------------------|
| 1    |        | 2026-01-15T09:00:00Z | 2026-01-15T09:00:00Z | agent@example.com | agent@example.com | false      | aB2cnoP8qrS9= | demo   | search-api   | search            | search            |
+------+--------+----------------------+----------------------+-------------------+-------------------+------------+---------------+--------+--------------+-------------------+-------------------+

After this fix — the jq projection is applied before formatting:

+------+--------------+-------------+
| id   | service      | admin_teams |
+===================================+
| 587  | edge-backend | [ops]       |
|------+--------------+-------------|
| 588  | edge-backend | [ops]       |
|------+--------------+-------------|
| 1104 | gateway      | [frontend]  |
|------+--------------+-------------|
| 1    | search-api   | [search]    |
+------+--------------+-------------+

Root cause

Config::from_env resolves output_format with an env fallback (DD_OUTPUT / PUP_OUTPUT), which is why a nested pup process inherits --output. jq had no equivalent fallback — it was hardcoded to None and only ever set from the literal --jq CLI flag. PUP_FILTER is already injected into every extension's environment (src/extensions/exec.rs) for exactly this purpose, but nothing read it back.

Fix

One line in src/config.rs — give jq the same env fallback output_format already has:

jq: env_or("PUP_FILTER", None),

Precedence is preserved: an explicit --jq flag still overrides the env (main.rs applies it after Config::from_env). Top-level pup behavior is unchanged when PUP_FILTER is unset; a manually-exported PUP_FILTER is now honored, matching the existing unguarded PUP_OUTPUT behavior.

Testing

  • Extended config::tests::test_pup_env_inherited_by_child to cover PUP_FILTER (asserts None when unset, Some(expr) when set).
  • cargo fmt --check, cargo clippy -- -D warnings, cargo build --release all clean.
  • Manually verified the repro end-to-end with the patched binary on PATH.

Docs

Added PUP_FILTER to the env-var table in docs/EXTENSIONS.md and extended the "read back by a child pup process" note.

@jkirsteins jkirsteins force-pushed the janis.kirsteins/jq-env-fallback branch from d4ed0bd to 65b586e Compare July 2, 2026 14:34
@jkirsteins jkirsteins marked this pull request as ready for review July 2, 2026 14:52
@jkirsteins jkirsteins requested a review from a team as a code owner July 2, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants