atmos icon indicating copy to clipboard operation
atmos copied to clipboard

Support --query flag with --provenance

Open osterman opened this issue 4 months ago • 0 comments

Describe the Feature

Add support for using --query and --provenance flags together in atmos describe component.

Expected Behavior

Users should be able to filter provenance output using the --query flag:

# Query for a map section with provenance annotations
atmos describe component vpc -s prod --provenance --query .vars

# Query for a scalar value (returns clean value without annotations)
atmos describe component vpc -s prod --provenance --query .vars.cidr

Map results should render with provenance annotations:

cidr: "10.100.0.0/16"                           # ● [1] orgs/acme/prod/us-east-2.yaml:10
name: vpc                                       # ○ [3] catalog/vpc/defaults.yaml:9

Scalar results should return the clean value (provenance annotations can't be added to scalars):

10.100.0.0/16

Current Behavior

Currently, --query and --provenance don't work together. The command returns an error:

invalid component: provenance rendering requires a map, got <type>

Use Case

This feature would be useful for:

  1. Focused provenance inspection - See provenance for just the section you care about (e.g., only .vars)
  2. Debugging specific values - Quickly check where a single value came from
  3. Automation - Scripts can query specific paths and get provenance when needed

Workaround

Currently, users must pipe provenance output through external tools:

# Instead of: atmos describe component vpc -s prod --provenance --query .vars
# Use:
atmos describe component vpc -s prod --provenance | yq '.vars'

However, this doesn't preserve provenance annotations since yq strips YAML comments.

Implementation Notes

The fix requires:

  1. Apply query before filtering computed fields
  2. Check if query result is a map:
    • If map → render with provenance (with filtering if needed)
    • If scalar/array → fall back to standard output without provenance
  3. Update FilterComputedFields to only apply when rendering full component (no query)

See attempted implementation in PR #1635 (commits reverted) for reference.

References

  • PR #1635 - Provenance tracking blog post
  • Related: /cli/commands/describe/component documentation

osterman avatar Oct 16 '25 02:10 osterman