Skip to content

Add --query (shorthand -q) flag to all atmos describe <subcommand> commands - #920

Merged
Andriy Knysh (aknysh) merged 41 commits into
mainfrom
add-vars-parameter
Jan 8, 2025
Merged

Andriy Knysh (aknysh) merged 41 commits into
mainfrom
add-vars-parameter

Conversation

@aknysh

@aknysh Andriy Knysh (aknysh) commented Jan 8, 2025 •

Copy link
Copy Markdown
Member

what

  • Add --query (shorthand -q) flag to all atmos describe <subcommand> commands
  • Update docs

why

  • Query (and filter) the results of atmos describe <subcommand> commands using yq expressions
  • Before, an external yq or jq binary was required to query/filter the results of atmos describe commands. With the yq functionality now embedded in Atmos, installing the yq binary is not required

examples

atmos describe component vpc -s plat-ue2-prod --query .vars
atmos describe component vpc -s plat-ue2-prod -q .vars.tags
atmos describe component vpc -s plat-ue2-prod -q .settings
atmos describe component vpc -s plat-ue2-prod --query .metadata.inherits

atmos describe stacks -q keys  # this produces the same result as the native `atmos list stacks` command

atmos describe config -q .stacks.base_path

atmos describe workflows -q '.0 | keys'

atmos describe affected -q <yq-expression>

atmos describe dependents -q <yq-expression>

references

Summary by CodeRabbit

Release Notes for Atmos v1.140.0

  • New Features

    • Added --query flag across multiple describe commands to filter results using YQ expressions.
    • Enhanced command-line querying capabilities for components, stacks, workflows, and configuration.
  • Improvements

    • Updated error handling in various commands.
    • Improved path resolution and configuration management.
    • Enhanced dependency management.
  • Dependency Updates

    • Added new dependencies including yq/v4 and several indirect dependencies.
    • Updated Go module dependencies.
  • Documentation

    • Updated CLI command documentation to reflect new querying functionality.
    • Added examples for new query-based commands.
  • Chores

    • Updated Atmos version in example configurations.
    • Minor code reorganization and import statement adjustments.

@mergify

mergify Bot commented Jan 8, 2025

Copy link
Copy Markdown
Contributor

💥 This pull request now has conflicts. Could you fix it Andriy Knysh (@aknysh)? 🙏

@mergify mergify Bot added the conflict This PR has conflicts label Jan 8, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
internal/exec/describe_stacks.go (1)

116-126: Consider using a more descriptive variable name than 'res'.

While the logic is solid, consider renaming res to something more descriptive like queryResult or stacksMapResult to better convey its purpose.

-	var res any
+	var queryResult any

	if query != "" {
-		res, err = u.EvaluateYqExpression(atmosConfig, finalStacksMap, query)
+		queryResult, err = u.EvaluateYqExpression(atmosConfig, finalStacksMap, query)
		if err != nil {
			return err
		}
	} else {
-		res = finalStacksMap
+		queryResult = finalStacksMap
	}

-	err = printOrWriteToFile(format, file, res)
+	err = printOrWriteToFile(format, file, queryResult)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c01a353 and a8a66f1.

📒 Files selected for processing (4)
  • go.mod (8 hunks)
  • internal/exec/describe_stacks.go (3 hunks)
  • internal/exec/utils.go (3 hunks)
  • pkg/config/const.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/config/const.go
  • go.mod
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Summary
🔇 Additional comments (6)
internal/exec/describe_stacks.go (2)

58-58: LGTM! Flag retrieval changes are consistent.

The changes maintain consistency in flag retrieval patterns across the function, with proper error handling.

Also applies to: 97-100


127-127: LGTM! Clean integration with existing output handling.

The query evaluation is well-integrated into the existing flow, maintaining backward compatibility while adding the new query functionality.

internal/exec/utils.go (4)

53-53: LGTM! The query flag is correctly added to commonFlags.

The placement ensures the flag will be properly handled and removed before passing arguments to underlying tools.


990-1001: LGTM! Query flag processing follows established patterns.

The implementation correctly handles both flag formats and includes proper error handling.


245-245: LGTM! Query field is properly integrated.

The field is correctly populated in the ConfigAndStacksInfo struct, maintaining consistency with other command-line arguments.


53-53: Verify query flag integration with describe commands.

Let's ensure the query flag is properly integrated across all describe commands.

Run this script to verify the integration:

Also applies to: 245-245, 990-1001

✅ Verification successful

Query flag integration verified successfully across describe commands

The query flag is properly implemented and consistently integrated across all describe commands, with proper parsing and execution flow.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify query flag integration in describe commands

# Test 1: Find all describe commands that should support the query flag
echo "Checking describe commands for query flag support..."
ast-grep --pattern 'func.*Cmd.*describe.*\(.*\).*{
  $$$
}'

# Test 2: Verify query flag processing in these commands
echo "Checking query flag processing..."
rg -A 5 'Query.*=.*argsAndFlagsInfo\.Query'

Length of output: 585


Script:

#!/bin/bash
# Find query flag definition and describe commands
echo "=== Query flag definition ==="
rg -A 3 'Query.*string.*[`"]query[`"]'

echo -e "\n=== Describe command implementations ==="
ast-grep --pattern 'func.*describe.*Command.*\(.*\).*{
  $$$
}'

echo -e "\n=== Query value usage ==="
rg -A 5 'configAndStacksInfo.*Query'

Length of output: 664


Script:

#!/bin/bash
# Broader search for query-related code
echo "=== Query flag definitions (broader search) ==="
rg -i "query.*flag" -A 3

echo -e "\n=== Describe command implementations (alternative pattern) ==="
rg "func.*[Dd]escribe" -A 5

echo -e "\n=== Query parameter flow ==="
rg -i "query" internal/exec/utils.go -A 3

Length of output: 21277

@aknysh
Andriy Knysh (aknysh) merged commit 66badb5 into main Jan 8, 2025
@aknysh
Andriy Knysh (aknysh) deleted the add-vars-parameter branch January 8, 2025 20:47
@mergify mergify Bot removed the needs-cloudposse Needs Cloud Posse assistance label Jan 8, 2025
@github-actions

github-actions Bot commented Jan 8, 2025

Copy link
Copy Markdown

These changes were released in v1.140.0.

@coderabbitai coderabbitai Bot mentioned this pull request Oct 3, 2025

This branch was successfully deployed

No deployments
preview — a8a66f14 Deployed Jan 8, 2025 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minor New features that do not break anything

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants