10000 Configure YAML formatting in atmos describe commands by Cerebrovinny · Pull Request #1180 · cloudposse/atmos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Configure YAML formatting in atmos describe commands #1180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 52 commits into
base: main
Choose a base branch
from

Conversation

Cerebrovinny
Copy link
Collaborator
@Cerebrovinny Cerebrovinny commented Mar 30, 2025

what

This PR makes the indentation and empty components configurable trough atmos.yaml file.

why

Evidence:
custom tab width: 4
Screenshot 2025-03-31 at 13 06 49

tab width: 2 (default config)
Screenshot 2025-03-31 at 13 07 12

Include Empty False (default config)
Screenshot 2025-03-31 at 13 07 42

# Atmos Describe Settings
describe:
  settings:
    include_empty: false

# Global settings
settings:
  terminal:
    tab_width: 4 # default should be 2

references

Summary by CodeRabbit

  • New Features

    • Introduced a new configuration section for enhanced output display settings.
    • Added a terminal option to customize YAML indentation width.
    • Enhanced functionality for handling empty sections in stack descriptions.
  • Refactor

    • Streamlined configuration handling for all output and display commands to improve consistency.
    • Updated output routines to leverage enhanced configuration options.
    • Replaced logging with a new structured logging library across multiple commands.
    • Improved YAML processing to support configurable indentation and error handling.
    • Added recursive filtering of empty sections in output data based on configuration.
  • Style

    • Standardized YAML formatting across configuration snapshots for better readability.
    • Adjusted indentation in test expectations and example configurations for consistency.
  • Tests

    • Expanded test coverage to validate new output formatting and empty section filtering.
    • Added tests for configuration struct fields and output formatting options.
    • Introduced tests for output writing functions and stack description filtering.
  • Documentation

    • Updated terminal configuration docs to include the new indentation setting.

@Cerebrovinny Cerebrovinny requested a review from Copilot March 30, 2025 21:40
Copy link
@Copilot 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

This PR introduces CLI configuration capabilities to the file output functions and adds logic to optionally skip empty sections in the describe commands. Key changes include:

  • Adding functions (PrintAsYAMLWithConfig and ConvertToYAML with options) to support custom YAML formatting.
  • Introducing new CLI config elements (DescribeSettings, Describe) and a TabWidth option in the Terminal settings.
  • Adjusting various describe command functions to pass the CLI configuration to output functions.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/utils/yaml_utils.go Added custom YAML output functions and support for configurable indentation options.
pkg/schema/schema.go Introduced DescribeSettings and Describe; added TabWidth to Terminal settings.
internal/exec/file_utils.go Modified printOrWriteToFile signature and logic to use atmosConfig and YAML options.
internal/exec/describe_workflows.go Updated printOrWriteToFile calls to pass atmosConfig.
internal/exec/describe_stacks.go Updated printOrWriteToFile calls and added logic to optionally skip empty sections.
internal/exec/describe_dependents.go Updated printOrWriteToFile calls to pass atmosConfig.
internal/exec/describe_config.go Updated printOrWriteToFile calls to pass atmosConfig.
internal/exec/describe_component.go Updated variable ordering and printOrWriteToFile calls to pass atmosConfig.
internal/exec/describe_affected.go Updated printOrWriteToFile calls to pass atmosConfig and CLIConfig consistency.

@Cerebrovinny Cerebrovinny added the minor New features that do not break anything label Mar 30, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 30, 2025
@github-actions github-actions bot added size/l and removed size/m labels Mar 30, 2025
Copy link
codecov bot commented Mar 31, 2025

Codecov Report

Attention: Patch coverage is 51.38889% with 70 lines in your changes missing coverage. Please review.

Project coverage is 33.06%. Comparing base (c87cd51) to head (fe1d909).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/utils/yaml_utils.go 33.33% 36 Missing and 4 partials ⚠️
internal/exec/describe_stacks.go 27.27% 6 Missing and 2 partials ⚠️
internal/exec/describe_component.go 44.44% 5 Missing ⚠️
internal/exec/helmfile.go 0.00% 4 Missing ⚠️
internal/exec/helmfile_generate_varfile.go 0.00% 3 Missing ⚠️
internal/exec/describe_affected.go 0.00% 2 Missing ⚠️
internal/exec/terraform.go 71.42% 2 Missing ⚠️
internal/exec/terraform_generate_varfile.go 0.00% 2 Missing ⚠️
internal/exec/describe_config.go 0.00% 1 Missing ⚠️
internal/exec/describe_dependents.go 0.00% 1 Missing ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1180      +/-   ##
==========================================
+ Coverage   32.89%   33.06%   +0.16%     
==========================================
  Files         223      224       +1     
  Lines       23791    23890      +99     
==========================================
+ Hits         7827     7899      +72     
- Misses      14798    14816      +18     
- Partials     1166     1175       +9     
Flag Coverage Δ
unittests 33.06% <51.38%> (+0.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Cerebrovinny Cerebrovinny requested a review from Copilot March 31, 2025 07:29
Copy link
@Copilot 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

This PR enhances YAML output functionality by introducing CLI configuration for YAML printing, handling nil configurations, and skipping empty sections in describe commands.

  • Adds a configurable indentation option and refactors YAML conversion to accept custom options.
  • Updates multiple functions to pass pointers for configuration and adds error handling for nil configurations.
  • Introduces new Describe settings in the schema for controlling empty section inclusion.

Reviewed Changes

Copilot reviewed 19 out of 20 changed files in this pull request and generated no comments.

File Description
pkg/utils/yaml_utils.go Refactors YAML conversion to use encoder with optional indentation.
pkg/schema/schema.go Adds Describe and DescribeSettings types for CLI config.
internal/exec/* Updates functions to pass a pointer for CLI config and adds nil checks.
Files not reviewed (1)
  • tests/snapshots/TestCLICommands_atmos_describe_config.stdout.golden: Language not supported
Comments suppressed due to low confidence (2)

internal/exec/describe_stacks.go:421

  • [nitpick] Consider updating or removing the placeholder comment ("pending Erik accept") to clarify the intended behavior for including empty sections. Use a clear TODO or remove it if no longer needed.
includeEmpty := true // Default to true if setting is not provided // pending Erik accept

internal/exec/describe_affected.go:317

  • Ensure consistent use of the CLI configuration pointer in this function; if both calls are meant to use the same configuration, consider using '&a.CLIConfig' for both printOrWriteToFile calls.
err = printOrWriteToFile(&atmosConfig, a.Format, a.OutputFile, res)

@github-actions github-actions bot added size/xl and removed size/l labels Mar 31, 2025
Copy link
mergify bot commented Mar 31, 2025

Warning

This PR exceeds the recommended limit of 1,000 lines.

Large PRs are difficult to review and may be rejected due to their size.

Please verify that this PR does not address multiple issues.
Consider refactoring it into smaller, more focused PRs to facilitate a smoother review process.

@Cerebrovinny Cerebrovinny changed the title Add CLI config to file output funcs; skip empty sections Configure YAML formatting in atmos describe commands Mar 31, 2025
@Cerebrovinny Cerebrovinny marked this pull request as ready for review March 31, 2025 12:11
@Cerebrovinny Cerebrovinny requested a review from a team as a code owner March 31, 2025 12:11
Copy link
Contributor
coderabbitai bot commented Mar 31, 2025
📝 Walkthrough

Walkthrough

This pull request updates several command and utility functions throughout the codebase to pass a pointer to the configuration structure (typically atmosConfig or CLIConfig) rather than a format string. Changes apply across multiple describe commands, Helmfile and Terraform functionality, YAML utilities, and associated tests. New logic is introduced for handling empty sections in stack descriptions, and additional settings—such as a new terminal tab width—have been added to the schema and documentation. These modifications affect function signatures, parameter handling, and the configuration-driven formatting of YAML output.

Changes

File(s) Change Summary
internal/exec/describe_affected.go, describe_component.go, describe_config.go, describe_dependents.go, describe_stacks.go, describe_workflows.go Updated calls to printOrWriteToFile to pass a pointer to the configuration (atmosConfig/CLIConfig) instead of a format string; added empty section filtering logic in stacks command.
internal/exec/file_utils.go, file_utils_test.go Modified the printOrWriteToFile signature to include a configuration pointer; enhanced YAML output with dynamic tab width based on terminal settings; added tests for YAML formatting and error handling.
internal/exec/helmfile.go, helmfile_generate_varfile.go, terraform.go, terraform_generate_varfile.go, utils.go, workflow_utils.go Changed calls to YAML printing functions to pass the configuration by reference for consistent handling.
pkg/describe/describe_stacks_test.go Introduced helper functions and test cases to validate empty section filtering in stack descriptions.
pkg/schema/schema.go, schema_test.go Added new types DescribeSettings and Describe, updated AtmosConfiguration with a Describe field, and introduced a TabWidth field in the Terminal struct.
pkg/utils/yaml_utils.go Revised YAML utility functions to accept a configuration pointer, added a nil check with error return (ErrNilAtmosConfig), and enabled dynamic indentation based on configuration.
tests/snapshots/* Reformatted YAML configuration snapshots for uniform indentation and structure without altering underlying data.
website/docs/cli/configuration/terminal.mdx Added a new configuration option (tab_width: 4) to the terminal settings documentation.
internal/exec/filter_utils.go Added new interface and implementation to filter empty sections from nested maps; introduced utility to extract include_empty setting from configuration.
examples/demo-stacks/component.yaml Added a new demo component YAML configuration file with detailed component and stack settings.
internal/exec/template_funcs_store_test.go Adjusted expected YAML indentation in test for template functions store.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Cmd as ExecuteDescribeStacksCmd
    participant Config as atmosConfig
    participant Printer as printOrWriteToFile

    User->>Cmd: Execute describe stacks command
    Cmd->>Config: Retrieve configuration settings
    Note right of Cmd: Determine includeEmpty flag from config
    Cmd-->>Cmd: Iterate over stack sections
    alt Section not empty or includeEmpty enabled
      Cmd->>Printer: Call printOrWriteToFile(&atmosConfig, ...)
    else Section is empty and includeEmpty disabled
      Note right of Cmd: Skip empty section
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
YAML formatting configurable (DEV-2918)
Option to hide empty blocks (DEV-2918) The implementation initializes the flag to include empty sections by default, making it unclear if it meets the intended default behavior to hide empty blocks.

Possibly related PRs

Suggested reviewers

  • osterman
  • aknysh

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
internal/exec/file_utils.go (1)

52-56: ⚠️ Potential issue

File permissions could be more restrictive

When writing files that might contain sensitive configuration data, it's best to use more restrictive permissions.

-			err = os.WriteFile(file, []byte(y), 0o644)
+			err = os.WriteFile(file, []byte(y), 0o600)
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 54-55: internal/exec/file_utils.go#L54-L55
Added lines #L54 - L55 were not covered by tests

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

421-426: Clarify IncludeEmpty default handling.

The logic defaults includeEmpty to true if atmosConfig.Describe.Settings.IncludeEmpty is nil. Confirm that this behavior aligns with user expectations and is tested to prevent surprises.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 421-424: internal/exec/describe_stacks.go#L421-L424
Added lines #L421 - L424 were not covered by tests

pkg/utils/yaml_utils.go (2)

30-41: Expose additional tags if needed.

Adding AtmosYamlTags and ErrNilAtmosConfig is helpful. Consider documenting AtmosYamlTags usage in your README or wiki to guide future maintainers.


49-73: Encourage test coverage on indentation logic.

PrintAsYAMLWithConfig reads TabWidth from atmosConfig.Settings.Terminal; coverage ensures that unexpected zero or negative values default to 2. Please add tests for these edge cases.

🧰 Tools
🪛 golangci-lint (1.64.8)

[error] 69-69: error is not nil (line 65) but it returns nil

(nilerr)

🪛 GitHub Check: codecov/patch

[warning] 52-53: pkg/utils/yaml_utils.go#L52-L53
Added lines #L52 - L53 were not covered by tests

pkg/describe/describe_stacks_test.go (4)

269-299: Good approach for total section counting.

countSections helps validate empty-section filtering. Consider also counting sections for Helmfile components for completeness if applicable.


300-324: Restrict repeated lookups.

countComponentSections repeatedly checks map presence. Minor efficiency could be gained by short-circuiting if any submap is nil. Optional improvement.


338-359: Solid test for stack-level filtering.

TestDescribeStacksWithEmptySectionFilteringAllStacks verifies total sections. Possibly add a negative test verifying no sections appear if everything is empty.


360-383: Great coverage for component filtering.

TestDescribeStacksWithEmptySectionFilteringComponent is similarly thorough. Adding more varied components could better stress-test the logic.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 448bab5 and 0719308.

📒 Files selected for processing (24)
  • internal/exec/describe_affected.go (2 hunks)
  • internal/exec/describe_component.go (2 hunks)
  • internal/exec/describe_config.go (1 hunks)
  • internal/exec/describe_dependents.go (1 hunks)
  • internal/exec/describe_stacks.go (2 hunks)
  • internal/exec/describe_workflows.go (1 hunks)
  • internal/exec/file_utils.go (1 hunks)
  • internal/exec/file_utils_test.go (1 hunks)
  • internal/exec/helmfile.go (1 hunks)
  • internal/exec/helmfile_generate_varfile.go (1 hunks)
  • internal/exec/terraform.go (2 hunks)
  • internal/exec/terraform_generate_varfile.go (1 hunks)
  • internal/exec/utils.go (1 hunks)
  • internal/exec/workflow_utils.go (1 hunks)
  • pkg/describe/describe_stacks_test.go (1 hunks)
  • pkg/schema/schema.go (3 hunks)
  • pkg/schema/schema_test.go (1 hunks)
  • pkg/utils/yaml_utils.go (6 hunks)
  • tests/snapshots/TestCLICommands_atmos_describe_config.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_describe_config_-f_yaml.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_describe_config_imports.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_describe_configuration.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_stacks_with_relative_paths.stdout.golden (1 hunks)
  • website/docs/cli/configuration/terminal.mdx (1 hunks)
🧰 Additional context used
🧬 Code Definitions (9)
internal/exec/workflow_utils.go (1)
pkg/utils/yaml_utils.go (1)
  • PrintAsYAMLToFileDescriptor (76-87)
internal/exec/terraform.go (1)
pkg/utils/yaml_utils.go (1)
  • PrintAsYAMLToFileDescriptor (76-87)
internal/exec/terraform_generate_varfile.go (1)
pkg/utils/yaml_utils.go (1)
  • PrintAsYAMLToFileDescriptor (76-87)
internal/exec/helmfile.go (1)
pkg/utils/yaml_utils.go (1)
  • PrintAsYAMLToFileDescriptor (76-87)
internal/exec/helmfile_generate_varfile.go (1)
pkg/utils/yaml_utils.go (1)
  • PrintAsYAMLToFileDescriptor (76-87)
internal/exec/describe_component.go (2)
pkg/config/config.go (1)
  • InitCliConfig (25-62)
pkg/schema/schema.go (1)
  • ConfigAndStacksInfo (375-443)
internal/exec/utils.go (1)
pkg/utils/yaml_utils.go (1)
  • PrintAsYAMLToFileDescriptor (76-87)
internal/exec/file_utils.go (2)
pkg/schema/schema.go (3)
  • AtmosConfiguration (23-56)
  • Settings (717-721)
  • Terminal (200-207)
pkg/utils/yaml_utils.go (3)
  • YAMLOptions (103-105)
  • PrintAsYAMLWithConfig (50-73)
  • ConvertToYAML (108-125)
pkg/utils/yaml_utils.go (3)
pkg/utils/config_utils.go (1)
  • ExtractAtmosConfig (8-17)
pkg/schema/schema.go (3)
  • AtmosConfiguration (23-56)
  • Settings (717-721)
  • Terminal (200-207)
pkg/utils/highlight_utils.go (1)
  • HighlightCodeWithConfig (75-147)
🪛 GitHub Check: codecov/patch
internal/exec/describe_config.go

[warning] 45-45: internal/exec/describe_config.go#L45
Added line #L45 was not covered by tests

internal/exec/terraform.go

[warning] 181-181: internal/exec/terraform.go#L181
Added line #L181 was not covered by tests

internal/exec/terraform_generate_varfile.go

[warning] 80-80: internal/exec/terraform_generate_varfile.go#L80
Added line #L80 was not covered by tests

internal/exec/helmfile.go

[warning] 89-89: internal/exec/helmfile.go#L89
Added line #L89 was not covered by tests

internal/exec/helmfile_generate_varfile.go

[warning] 65-65: internal/exec/helmfile_generate_varfile.go#L65
Added line #L65 was not covered by tests

internal/exec/describe_component.go

[warning] 74-77: internal/exec/describe_component.go#L74-L77
Added lines #L74 - L77 were not covered by tests


[warning] 90-90: internal/exec/describe_component.go#L90
Added line #L90 was not covered by tests

internal/exec/utils.go

[warning] 320-320: internal/exec/utils.go#L320
Added line #L320 was not covered by tests

internal/exec/describe_affected.go

[warning] 274-274: internal/exec/describe_affected.go#L274
Added line #L274 was not covered by tests


[warning] 317-317: internal/exec/describe_affected.go#L317
Added line #L317 was not covered by tests

internal/exec/file_utils.go

[warning] 54-55: internal/exec/file_utils.go#L54-L55
Added lines #L54 - L55 were not covered by tests

internal/exec/describe_dependents.go

[warning] 79-79: internal/exec/describe_dependents.go#L79
Added line #L79 was not covered by tests

internal/exec/describe_stacks.go

[warning] 139-139: internal/exec/describe_stacks.go#L139
Added line #L139 was not covered by tests


[warning] 421-424: internal/exec/describe_stacks.go#L421-L424
Added lines #L421 - L424 were not covered by tests


[warning] 428-433: internal/exec/describe_stacks.go#L428-L433
Added lines #L428 - L433 were not covered by tests

internal/exec/describe_workflows.go

[warning] 79-79: internal/exec/describe_workflows.go#L79
Added line #L79 was not covered by tests

pkg/utils/yaml_utils.go

[warning] 52-53: pkg/utils/yaml_utils.go#L52-L53
Added lines #L52 - L53 were not covered by tests


[warning] 76-79: pkg/utils/yaml_utils.go#L76-L79
Added lines #L76 - L79 were not covered by tests


[warning] 225-226: pkg/utils/yaml_utils.go#L225-L226
Added lines #L225 - L226 were not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Acceptance Tests (windows-latest, windows)
  • GitHub Check: Summary
🔇 Additional comments (43)
tests/snapshots/TestCLICommands_atmos_describe_configuration.stdout.golden (1)

3-63: Indentation formatting looks consistent

The changes show a uniform indentation style across all YAML sections. This aligns with the PR objective to standardize YAML formatting.

tests/snapshots/TestCLICommands_atmos_stacks_with_relative_paths.stdout.golden (1)

2-96: Consistent YAML indentation across all environment sections

The YAML structure maintains uniform indentation across all components sections for dev, prod, and staging environments. This improves readability and follows best practices.

tests/snapshots/TestCLICommands_atmos_describe_config_imports.stdout.golden (1)

3-166: Unified indentation style across configuration sections

The formatting changes maintain consistent indentation across all configuration sections. This standardization improves readability without altering functionality.

website/docs/cli/configuration/terminal.mdx (1)

33-33: Documentation added for the new tab_width setting

The new tab_width configuration option is properly documented with a clear explanation of its purpose and default value. This helps users understand how to customize YAML indentation.

tests/snapshots/TestCLICommands_atmos_describe_config.stdout.golden (1)

119-121: New "describe" configuration section added

A new section for "describe" settings has been added to the configuration structure. This sets up the foundation for the configurable YAML formatting features introduced in this PR.

internal/exec/describe_config.go (1)

45-45: Looking good - pointer passing for configuration control.

The change from passing a format string to passing a pointer to the entire configuration structure allows for more fine-grained control over output formatting based on user preferences. This aligns with the PR objective of enabling configurable indentation.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 45-45: internal/exec/describe_config.go#L45
Added line #L45 was not covered by tests

internal/exec/helmfile_generate_varfile.go (1)

65-65: Correctly updated to pass configuration by reference.

This change matches the updated function signature in PrintAsYAMLToFileDescriptor that now expects a pointer to atmosConfig, ensuring consistent formatting control across the application.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 65-65: internal/exec/helmfile_generate_varfile.go#L65
Added line #L65 was not covered by tests

tests/snapshots/TestCLICommands_atmos_describe_config_-f_yaml.stdout.golden (8)

3-12: Consistent indentation improves YAML readability.

The updated YAML formatting with consistent indentation provides better readability while maintaining the same data structure.


15-21: Uniformly indented YAML structure.

The consistent indentation in the helmfile section matches the formatting applied to other sections, creating a more unified appearance.


23-29: Standardized indentation in stacks section.

The indentation changes here maintain consistency with the rest of the document.


31-32: Log section formatting updated for consistency.

The log section now follows the same indentation pattern as other sections.


34-35: Settings section properly aligned.

Indentation consistency applied to the settings section.


39-39: Path array elements consistently indented.

The includeStackAbsolutePaths array elements follow the same indentation pattern.


41-41: Exclude paths follow consistent formatting.

The excludeStackAbsolutePaths array elements are properly indented.


46-47: Editorconfig section formatted with consistent style.

The validate section maintains the consistent indentation pattern established throughout the document.

internal/exec/workflow_utils.go (1)

46-46: Pointer to config passed correctly.

Changed to pass a pointer to atmosConfig instead of the value directly, matching the updated signature of PrintAsYAMLToFileDescriptor which now accepts a pointer to allow for configuration-driven formatting.

internal/exec/terraform.go (2)

132-132: Code updated to pass atmosConfig by reference

The change from atmosConfig to &atmosConfig updates the argument to match the updated function signature that now expects a pointer to AtmosConfiguration.


181-181:

✅ Verification successful

Code updated to pass atmosConfig by reference

Similar to the previous change, this updates the call to use a pointer to atmosConfig to match the updated function signature.


🏁 Script executed:

#!/bin/bash
# Verify the signature of PrintAsYAMLToFileDescriptor to confirm it requires a pointer
rg -A 3 "func PrintAsYAMLToFileDescriptor" pkg/utils/yaml_utils.go

Length of output: 214


Action: Code update verified – atmosConfig is now correctly passed by pointer.

The change in internal/exec/terraform.go now aligns perfectly with the function signature in pkg/utils/yaml_utils.go (i.e., func PrintAsYAMLToFileDescriptor(atmosConfig *schema.AtmosConfiguration, data any) error). The update to pass &atmosConfig is accurate and consistent with the expectations set by the function definition.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 181-181: internal/exec/terraform.go#L181
Added line #L181 was not covered by tests

internal/exec/terraform_generate_varfile.go (1)

80-80: Code updated to pass atmosConfig by reference

This change modifies the argument to match the updated function signature that now expects a pointer to AtmosConfiguration. The change ensures code consistency with the revisions to the PrintAsYAMLToFileDescriptor function.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 80-80: internal/exec/terraform_generate_varfile.go#L80
Added line #L80 was not covered by tests

internal/exec/helmfile.go (1)

89-89: Code updated to pass atmosConfig by reference

This change aligns with the updated PrintAsYAMLToFileDescriptor function signature. Using a pointer allows the function to access the YAML formatting settings from the configuration, supporting the configurable indentation feature mentioned in the PR objectives.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 89-89: internal/exec/helmfile.go#L89
Added line #L89 was not covered by tests

internal/exec/utils.go (1)

320-320: Code updated to pass atmosConfig by reference

This change mirrors the other updates, ensuring the parameter is passed by reference to match the revised function signature. This is part of the broader change to enable configurable YAML formatting through atmos.yaml.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 320-320: internal/exec/utils.go#L320
Added line #L320 was not covered by tests

internal/exec/describe_workflows.go (1)

79-79:

✅ Verification successful

Function modified to use configuration object instead of raw format string

The change from passing the format string directly to passing the full configuration object gives the function access to YAML formatting settings like tab width and component display preferences.


🏁 Script executed:

#!/bin/bash
# Verify the signature of printOrWriteToFile has been updated to accept the atmosConfig parameter
grep -A 5 "func printOrWriteToFile" internal/exec/file_utils.go

Length of output: 182


Verified: Configuration Object Passed to printOrWriteToFile

The function signature now accepts the full configuration object (atmosConfig *schema.AtmosConfiguration) as intended. The code in internal/exec/describe_workflows.go (line 79) is correctly updated to call the function with the configuration object, ensuring YAML formatting settings (like tab width and component display preferences) are properly handled.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 79-79: internal/exec/describe_workflows.go#L79
Added line #L79 was not covered by tests

internal/exec/describe_dependents.go (1)

79-79: Function signature updated to pass configuration settings

This change aligns with the PR objective of making YAML formatting configurable through atmos.yaml settings. The function now has access to tab width and empty component display preferences.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 79-79: internal/exec/describe_dependents.go#L79
Added line #L79 was not covered by tests

internal/exec/describe_component.go (2)

74-78: Configuration initialization moved outside conditional block

Good change - moving the atmosConfig initialization before the query conditional ensures it's always available regardless of whether a query is provided.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 74-77: internal/exec/describe_component.go#L74-L77
Added lines #L74 - L77 were not covered by tests


90-90: Function signature updated to pass configuration pointer

Consistent with changes in other files, now passing the full config object rather than just format string.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 90-90: internal/exec/describe_component.go#L90
Added line #L90 was not covered by tests

pkg/schema/schema_test.go (1)

40-72: Test added for new configuration options

Well-structured test that validates both TabWidth and IncludeEmpty settings. The test covers:

  1. Direct struct creation with TabWidth=4
  2. IncludeEmpty=false validation
  3. IncludeEmpty=true validation
  4. Complete AtmosConfiguration with both settings

This provides good coverage for the new configuration options introduced in this PR.

internal/exec/file_utils_test.go (1)

13-68: Good test coverage, well structured test cases

The test file provides thorough testing of the printOrWriteToFile function with different scenarios including:

  • Writing YAML and JSON to stdout
  • Writing to temporary files with proper cleanup
  • Error handling for invalid formats
  • Testing default behavior when TabWidth is 0

The test initializes the configuration properly with a custom tab width of 4 and verifies all expected outcomes.

internal/exec/describe_affected.go (2)

274-274:

❓ Verification inconclusive

Function signature update correctly implemented

The code correctly passes a pointer to the configuration structure rather than just the format string, aligning with the updated function signature in file_utils.go.


🏁 Script executed:

#!/bin/bash
# Check for test coverage of this line which static analysis flagged as untested
grep -r "ExecuteDescribeAffectedCmd.*test" --include="*.go" .

Length of output: 63


Function signature update correctly implemented; please confirm test coverage manually

The updated call to printOrWriteToFile with a pointer to the configuration structure is correct and aligns with the signature change in file_utils.go. However, the grep check for tests covering ExecuteDescribeAffectedCmd returned no results. Could you please verify manually that this functionality is covered by tests—or add appropriate tests if they're missing?

  • Verify or add test coverage for ExecuteDescribeAffectedCmd, especially around the call in internal/exec/describe_affected.go:274.
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 274-274: internal/exec/describe_affected.go#L274
Added line #L274 was not covered by tests


317-317:

❓ Verification inconclusive

Function signature update correctly implemented

The code correctly passes a pointer to the configuration structure rather than just the format string, maintaining consistency with the updated function signature in file_utils.go.


🏁 Script executed:

#!/bin/bash
# Check if this code path is tested
grep -r "atmosConfig.*printOrWriteToFile.*a.Query" --include="*.go" . | grep -v "describe_affected.go"

Length of output: 102


Attention: Verify Test Coverage for Updated Function Signature

  • The function signature update is correctly implemented. The updated call in internal/exec/describe_affected.go (line 317) passes a pointer to atmosConfig, consistent with the changes in file_utils.go.
  • However, the grep command did not yield any results outside describe_affected.go. This makes it unclear whether additional code paths invoking printOrWriteToFile are covered by tests.
  • Please manually verify that the relevant code path is adequately exercised by the test suite.
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 317-317: internal/exec/describe_affected.go#L317
Added line #L317 was not covered by tests

pkg/schema/schema.go (4)

14-16: Well-structured settings for describe command output

The DescribeSettings type is properly defined with appropriate YAML, JSON, and mapstructure tags. Using a pointer to bool for IncludeEmpty is a good choice as it allows for three states (true, false, nil) which enables proper handling of unset values.


19-21: Clean implementation of Describe structure

The Describe type follows the established pattern in the codebase, with appropriate serialization tags and a nested Settings field.


35-35: Configuration structure properly extended

The AtmosConfiguration struct has been correctly extended with the new Describe field, keeping consistent with existing patterns and properly tagged for serialization.


206-206: Tab width setting added to Terminal configuration

Good addition of the TabWidth field to the Terminal struct with appropriate serialization tags. Making it optional (with omitempty) allows for backward compatibility.

internal/exec/file_utils.go (3)

33-33: Updated function signature with pointer parameter

Good change to use a pointer to schema.AtmosConfiguration rather than passing the entire structure by value, which would be inefficient for large structs.


40-44: Tab width handling with sensible default

Nice implementation to extract the tab width from configuration with a fallback to the default value of 2 when not specified or set to an invalid value (≤ 0).


47-47: Updated YAML printing to use configuration

Good update to use the configuration-aware YAML printing function.

internal/exec/describe_stacks.go (1)

139-139: Validate coverage for the new pointer usage.

Consider adding a test to confirm that printOrWriteToFile is invoked with a valid pointer to atmosConfig, ensuring no regressions when the config is nil or modified at runtime.

Would you like a script that checks for tests covering this line?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 139-139: internal/exec/describe_stacks.go#L139
Added line #L139 was not covered by tests

pkg/utils/yaml_utils.go (4)

4-5: Imports look good.

No concerns about bytes or errors usage.


43-48: Add coverage for the fallback logic.

PrintAsYAML calls ExtractAtmosConfig and then delegates to PrintAsYAMLWithConfig. Include a test verifying correct behavior when data lacks config or is nil.


75-79: Check usage of PrintAsYAMLToFileDescriptor.

We see a nil-check and direct logging. Consider adding tests around scenarios like missing atmosConfig or unusual file descriptors to ensure robust error-handling.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 76-79: pkg/utils/yaml_utils.go#L76-L79
Added lines #L76 - L79 were not covered by tests


225-226: Test nil config error path.

UnmarshalYAMLFromFile returns ErrNilAtmosConfig if atmosConfig == nil. Confirm test coverage for that scenario, preventing unhandled edge cases.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 225-226: pkg/utils/yaml_utils.go#L225-L226
Added lines #L225 - L226 were not covered by tests

pkg/describe/describe_stacks_test.go (2)

325-337: Nice setup for test config.

setupEmptySectionFilteringTest is straightforward. If feasible, confirm it also handles partial initialization or override scenarios for includeEmpty.


384-389: Clever aggregator test.

TestDescribeStacksWithEmptySectionFiltering calls the other two tests, ensuring comprehensive coverage. This approach is maintainable and clear.

@osterman
Copy link
Member

I think include empty should also filter out "". Would that be easy?

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

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

11-130: Test structure for FilterEmptySections is comprehensive.

The test cases cover a wide range of scenarios including nested maps, mixed value types, and edge cases like empty inputs. This thorough testing will ensure robust filtering behavior in the codebase.

Consider using the assert package consistently instead of reflect.DeepEqual for more readable error messages:

- if !reflect.DeepEqual(result, tt.expected) {
-   t.Errorf("FilterEmptySections() = %v, want %v", result, tt.expected)
- }
+ assert.Equal(t, tt.expected, result)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c5f64b4 and 333629b.

📒 Files selected for processing (1)
  • internal/exec/filter_utils_test.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Summary
🔇 Additional comments (2)
internal/exec/filter_utils_test.go (2)

1-10: LGTM - Import structure follows package conventions.

The imports are properly organized and include all necessary dependencies for testing.


173-179: TestGetIncludeEmptySetting aligns with the PR objective for configurable empty components.

This test case verifies that the include_empty setting can be explicitly set to false, which supports the PR goal of making empty component settings configurable.

coderabbitai[bot]
coderabbitai bot previously approved these changes Apr 26, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Apr 26, 2025
Copy link
@Copilot 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

This PR introduces configurable YAML formatting for atmos describe commands by adding new configuration schema types for the describe command and a customizable terminal indentation (tab_width). It also updates multiple functions to pass the atmosConfig as a pointer and replaces legacy logging calls with structured logging.

  • Added DescribeSettings and Describe types to support describe command output configuration.
  • Introduced a Terminal tab_width field and updated PrintAsYAML/WriteToFile calls to use the new configuration.
  • Refactored logging calls and configuration handling in various commands.

Reviewed Changes

Copilot reviewed 29 out of 29 changed files in this pull request and generated no comments.

File Description
pkg/schema/schema.go Added ne 10000 w configuration types for describe commands and terminal tab_width setting.
pkg/describe/describe_stacks_test.go Added tests and helper functions for empty section filtering.
internal/exec/* Updated PrintAsYAMLToFileDescriptor and logging calls to use pointers and structured logging.
examples/demo-stacks/component.yaml Updated YAML example to include new configuration fields.

Copy link
mergify bot commented May 7, 2025

💥 This pull request now has conflicts. Could you fix it @Cerebrovinny? 🙏

@mergify mergify bot added the conflict This PR has conflicts label May 7, 2025
@milldr milldr self-assigned this May 8, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes May 11, 2025
AtmosYamlFuncExec = "!exec"
AtmosYamlFuncStore = "!store"
AtmosYamlFuncTemplate = "!template"
AtmosYamlFuncTerraformOutput = "!terraform.output"
AtmosYamlFuncEnv = "!env"
AtmosYamlFuncInclude = "!include"
AtmosYamlFuncGitRoot = "!repo-root"

// Default YAML formatting settings

Check failure

Code scanning / golangci-lint

Comment should end in a period Error

Comment should end in a period
return PrintAsYAMLWithConfig(&atmosConfig, data)
}

// getIndentFromConfig returns the configured tab width or the default value

Check failure

Code scanning / golangci-lint

Comment should end in a period Error

Comment should end in a period
Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
pkg/utils/yaml_utils.go (1)

249-249: 🛠️ Refactor suggestion

Update ConvertToYAML call to use DefaultYAMLIndent.

This call to ConvertToYAML doesn't use the new options parameter. Consider updating it for consistency.

-			y, err := ConvertToYAML(res)
+			y, err := ConvertToYAML(res, YAMLOptions{Indent: DefaultYAMLIndent})
♻️ Duplicate comments (2)
pkg/utils/yaml_utils.go (2)

34-40: ⚠️ Potential issue

Include AtmosYamlFuncInclude in AtmosYamlTags.

The AtmosYamlFuncInclude is defined as a constant but not included in the AtmosYamlTags slice, which may cause inconsistent behavior when processing YAML tags.

var (
	AtmosYamlTags = []string{
		AtmosYamlFuncExec,
		AtmosYamlFuncStore,
		AtmosYamlFuncTemplate,
		AtmosYamlFuncTerraformOutput,
		AtmosYamlFuncEnv,
+		AtmosYamlFuncInclude,
	}

122-122: 🛠️ Refactor suggestion

Sanitize file paths in debug logs.

Logging full file paths can expose directory structures or sensitive information. Consider sanitizing the path before logging.

-	log.Debug("WriteToFileAsYAMLWithConfig", "tabWidth", indent, "filePath", filePath)
+	sanitizedPath := filepath.Base(filePath)
+	log.Debug("WriteToFileAsYAMLWithConfig", "tabWidth", indent, "filePath", sanitizedPath)
🧹 Nitpick comments (3)
pkg/utils/yaml_utils.go (3)

29-30: Add periods to comments for consistency.

The comments for new constants should end with periods to maintain consistency with other comments in the codebase.

-	// Default YAML formatting settings
+	// Default YAML formatting settings.
	DefaultYAMLIndent = 2
🧰 Tools
🪛 GitHub Check: golangci-lint

[failure] 29-29:
Comment should end in a period


55-61: Add period to function comment.

Comment should end with a period to maintain consistency across the codebase.

-// getIndentFromConfig returns the configured tab width or the default value
+// getIndentFromConfig returns the configured tab width or the default value.
🧰 Tools
🪛 GitHub Check: golangci-lint

[failure] 55-55:
Comment should end in a period


158-273: Consider refactoring processCustomTags function in a future PR.

The processCustomTags function has high cognitive complexity (77 > 20). Consider decomposing it into smaller functions in a future PR to improve readability and maintainability.

🧰 Tools
🪛 golangci-lint (1.64.8)

[error] 158-158: cognitive complexity 77 of func processCustomTags is high (> 20)

(gocognit)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b9286ff and 1d4f74a.

📒 Files selected for processing (2)
  • internal/exec/filter_utils.go (1 hunks)
  • pkg/utils/yaml_utils.go (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/exec/filter_utils.go
🧰 Additional context used
🪛 GitHub Check: golangci-lint
pkg/utils/yaml_utils.go

[failure] 29-29:
Comment should end in a period


[failure] 55-55:
Comment should end in a period

🪛 golangci-lint (1.64.8)
pkg/utils/yaml_utils.go

[error] 78-78: error is not nil (line 75) but it returns nil

(nilerr)


[error] 158-158: cognitive complexity 77 of func processCustomTags is high (> 20)

(gocognit)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Summary
🔇 Additional comments (3)
pkg/utils/yaml_utils.go (3)

136-139: Use variadic parameters for YAMLOptions consistently.

The YAMLOptions struct is a good pattern for extensible configuration, but ensure it's used consistently throughout the codebase.


141-156: Clean implementation of YAML conversion with configurable indentation.

The new implementation of ConvertToYAML with options for indentation is well-structured and provides good flexibility.


288-290: Good defensive programming check.

The nil check for atmosConfig is a good defensive programming practice to prevent runtime panics.

Comment on lines +75 to 79
highlighted, err := HighlightCodeWithConfig(y, *atmosConfig, "yaml")
if err != nil {
// Fallback to plain text if highlighting fails
PrintMessage(y)
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix error handling behavior.

The function ignores the error from HighlightCodeWithConfig and returns nil instead of the error.

	highlighted, err := HighlightCodeWithConfig(y, *atmosConfig, "yaml")
	if err != nil {
		PrintMessage(y)
-		return nil
+		return err
	}
🧰 Tools
🪛 golangci-lint (1.64.8)

[error] 78-78: error is not nil (line 75) but it returns nil

(nilerr)

🤖 Prompt for AI Agents (early access)
In pkg/utils/yaml_utils.go around lines 75 to 79, the error returned from
HighlightCodeWithConfig is ignored and the function returns nil instead of
propagating the error. Modify the error handling to return the error received
from HighlightCodeWithConfig instead of nil, ensuring proper error propagation.

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 size/xl
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0