Skip to content

fix: Deprecated flags msg for experimental command #4146

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

Merged
merged 7 commits into from
Apr 14, 2025

Conversation

levkohimins
Copy link
Contributor

@levkohimins levkohimins commented Apr 9, 2025

Description

Fixes #4082.

TODOs

Read the Gruntwork contribution guidelines.

  • Update the docs.
  • Run the relevant tests successfully, including pre-commit checks.
  • Ensure any 3rd party code adheres with our license policy or delete this line if its not applicable.
  • Include release notes. If this PR is backward incompatible, include a migration guide.

Release Notes (draft)

Added / Removed / Updated [X].

Migration Guide

Summary by CodeRabbit

  • New Features

    • Improved the evaluation handling of deprecated and global flags with a flexible mechanism that activates under an experimental mode.
    • Enhanced configuration by linking to an external Terraform module for better integration.
  • Tests

    • Introduced integration tests to validate the refined flag behavior and ensure consistent operation.
  • Chores

    • Cleaned up configurations by removing an obsolete, unused test file.

@levkohimins levkohimins marked this pull request as ready for review April 9, 2025 19:41
Copy link

vercel bot commented Apr 9, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
terragrunt-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 9, 2025 8:11pm

Copy link
Contributor

coderabbitai bot commented Apr 9, 2025

📝 Walkthrough

Walkthrough

The changes enhance how deprecated flags are evaluated by introducing a new function type, EvaluateWrapperFunc, and integrating it into the flag handling process. The Flag struct now supports a customizable evaluation mechanism via its new field, and the flag creation functions have been updated to accept additional options. Additionally, a new option setter, WithEvaluateWrapper, has been introduced along with conditional logic in the global flags to respect the cli-redesign experiment flag. An integration test has been added to validate the behavior of the global --tf-path flag, and an unused configuration file was removed.

Changes

Files Change Summary
cli/flags/flag.go, cli/flags/flag_opts.go, cli/flags/global/flags.go Introduced EvaluateWrapperFunc and an evaluateWrapper field in the Flag struct; updated NewMovedFlag signature to accept options; added WithEvaluateWrapper option; and integrated conditional evaluation logic that checks the cli-redesign experiment flag.
test/integration_test.go Added TestGlobalFlagMoveStrictControl to verify that the relocated --tf-path flag behaves correctly depending on whether the cli-redesign experiment is enabled.
test/fixtures/cli-flag-hints/main.hcl Deleted the intentionally empty file.
test/fixtures/cli-flag-hints/terragrunt.hcl Modified to include a new terraform block with a source attribute pointing to an external Terraform module.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Flag
    participant EvaluateWrapper
    participant EvalFunction

    Caller->>Flag: Invoke RunAction
    Flag->>EvaluateWrapper: Call evaluateWrapper(evalFn)
    EvaluateWrapper->>EvaluateWrapper: Check if cli-redesign experiment enabled
    alt Experiment enabled
        EvaluateWrapper->>EvalFunction: Execute evalFn()
    else Experiment disabled
        EvaluateWrapper-->>Flag: Return nil (skip evaluation)
    end
    Flag-->>Caller: Complete action
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure that using the --tf-path flag enforces the requirement to enable the cli-redesign experiment (#4082)

Possibly related PRs

  • fix: Correct displaying deprecated flag warnings #3880: The changes in the main PR, which introduce a new evaluation mechanism for deprecated flags, are related to the retrieved PR, as both involve modifications to how deprecated flags are handled and displayed, particularly in the context of their movement to new commands.

Suggested reviewers

  • denis256
  • yhakbar
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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 to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai 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.

@yhakbar
Copy link
Collaborator

yhakbar commented Apr 9, 2025

I don't really understand what's happening here. Do you mind adding some more documentation in the way of comments to explain the intention here?

@levkohimins
Copy link
Contributor Author

levkohimins commented Apr 9, 2025

I don't really understand what's happening here. Do you mind adding some more documentation in the way of comments to explain the intention here?

We discussed that if --experiment cli-redesign is not specified, we should not show deprecated messages suggesting to use the experimental command.
I don't know what exactly to add to the documentation. #4082

@yhakbar
Copy link
Collaborator

yhakbar commented Apr 9, 2025

I don't know what exactly to add to the documentation. #4082

I don't think someone reading this:

type EvaluateWrapperFunc func(ctx context.Context, evalFn func(ctx context.Context) error) error

// Flag is a wrapper for `cli.Flag` that avoids displaying deprecated flags in help, but registers their flag names and environment variables.
type Flag struct {
	cli.Flag
	evaluateWrapper EvaluateWrapperFunc
	deprecatedFlags DeprecatedFlags
}

// NewFlag returns a new Flag instance.
func NewFlag(new cli.Flag, opts ...Option) *Flag {
	flag := &Flag{
		Flag: new,
		evaluateWrapper: func(ctx context.Context, evalFn func(ctx context.Context) error) error {
			return evalFn(ctx)
		},
	}

Is going to know what EvaluateWrapperFunc does, why you'd want to use it, or how it's supposed to be used. Adding some context in comments explaining why it's useful, and how someone should use it would help for long term maintainability.

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)
cli/flags/flag.go (1)

16-147: 💡 Verification agent

🧩 Analysis chain

Consider adding integration tests for the new evaluation wrapper functionality

The changes introduce a significant functional enhancement that could benefit from dedicated tests to verify the wrapper's behavior in different scenarios, especially with the experimental flag mentioned in the PR objectives.


🏁 Script executed:

#!/bin/bash
# Check if there are tests for the new EvaluateWrapperFunc functionality

echo "Searching for tests related to EvaluateWrapperFunc..."
rg -l "EvaluateWrapperFunc" --type go
echo "Searching for tests in the flags package..."
rg -l "TestFlag|test.*Flag|flag.*Test" --type go

Length of output: 617


Action: Add targeted integration tests for the evaluation wrapper functionality

While there are tests in the flags package (e.g. in cli/flags/flag_test.go and several integration tests under the test/ directory), none appear to specifically exercise the new behavior introduced by the EvaluateWrapperFunc. This wrapper is critical for controlling strict evaluation in scenarios involving deprecated flags. I recommend adding explicit integration tests that simulate:

  • Cases where a custom evaluation wrapper modifies or intercepts the evaluation flow.
  • Scenarios where the deprecated flag’s evaluation is invoked, ensuring that any modifications introduced by the wrapper are correctly handled.
  • Error paths to confirm proper error propagation when the wrapper or the underlying evaluation function fails.

These tests will help ensure that the new functionality behaves as expected across different use cases.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8eb1ba3 and 658ae42.

📒 Files selected for processing (2)
  • cli/flags/flag.go (4 hunks)
  • cli/flags/global/flags.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • cli/flags/global/flags.go
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code for quality and correctness. Make sure that the Go code follows best practices, is performant, and is easy to understand and maintain.

**/*.go: Review the Go code for quality and correctness. Make sure that the Go code follows best practices, is performant, and is easy to understand and maintain.

  • cli/flags/flag.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Pull Request has non-contributor approval
🔇 Additional comments (5)
cli/flags/flag.go (5)

23-23: LGTM! Added field for evaluation customization

This field enables the customization of flag evaluation behavior, allowing for conditional messaging around deprecated flags.


31-33: LGTM! Default implementation preserves original behavior

The default implementation correctly maintains backward compatibility by simply executing the provided evaluation function without modification.


43-44: LGTM! Enhanced flexibility with options pattern

The updated NewMovedFlag function properly leverages the variadic options pattern, making the flag creation API more flexible and extensible.


131-131: LGTM! Using the wrapper for deprecated flag evaluation

Correctly applies the evaluation wrapper to control how deprecated flags are evaluated.


147-147: LGTM! Consistent wrapper usage

This change ensures consistent use of the evaluation wrapper pattern throughout the code, maintaining a uniform approach to flag evaluation.

Comment on lines +16 to +18
// EvaluateWrapperFunc represents a function that is used to wrap the `Evaluate(ctx context.Context) error` strict control method.
// Which can be passed as an option `WithEvaluateWrapper` to `NewFlag(...)` to control the behavior of strict control evaluation.
type EvaluateWrapperFunc func(ctx context.Context, evalFn func(ctx context.Context) error) error
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve documentation for EvaluateWrapperFunc

The documentation explains the technical purpose of EvaluateWrapperFunc, but lacks context about why someone would use this wrapper and specific use cases. According to the PR comments, this was designed to prevent deprecated messages from being displayed when the --experiment cli-redesign flag is not specified.

// EvaluateWrapperFunc represents a function that is used to wrap the `Evaluate(ctx context.Context) error` strict control method.
// Which can be passed as an option `WithEvaluateWrapper` to `NewFlag(...)` to control the behavior of strict control evaluation.
+ // It's primarily used to conditionally show deprecated flag messages, especially when experimental features
+ // like the cli-redesign are enabled or disabled.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// EvaluateWrapperFunc represents a function that is used to wrap the `Evaluate(ctx context.Context) error` strict control method.
// Which can be passed as an option `WithEvaluateWrapper` to `NewFlag(...)` to control the behavior of strict control evaluation.
type EvaluateWrapperFunc func(ctx context.Context, evalFn func(ctx context.Context) error) error
// EvaluateWrapperFunc represents a function that is used to wrap the `Evaluate(ctx context.Context) error` strict control method.
// Which can be passed as an option `WithEvaluateWrapper` to `NewFlag(...)` to control the behavior of strict control evaluation.
// It's primarily used to conditionally show deprecated flag messages, especially when experimental features
// like the cli-redesign are enabled or disabled.
type EvaluateWrapperFunc func(ctx context.Context, evalFn func(ctx context.Context) error) error

@levkohimins levkohimins merged commit a4f8133 into main Apr 14, 2025
8 of 9 checks passed
@levkohimins levkohimins deleted the bug/warn-global-flag branch April 14, 2025 16:47
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.

--tf-path tries to make you use cli-redesign
2 participants