Skip to content

chore: hclfmt hclvalidate validate-inputs as deprecated commands#4196

Merged
lev-ok merged 5 commits intomainfrom
feat/strict-control-deprecated-hcl-commands
Apr 22, 2025
Merged

chore: hclfmt hclvalidate validate-inputs as deprecated commands#4196
lev-ok merged 5 commits intomainfrom
feat/strict-control-deprecated-hcl-commands

Conversation

@lev-ok
Copy link
Copy Markdown
Contributor

@lev-ok lev-ok commented Apr 22, 2025

Description

Adding hclfmt hclvalidate validate-inputs commands under strict cli-redesign control.

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

    • Added support for deprecated environment variables for relevant HCL format and validate command flags.
    • Introduced a new strict control to prevent the use of deprecated commands.
  • Bug Fixes

    • Updated command naming conventions for consistency across the CLI.
  • Refactor

    • Unified and improved the handling of deprecated commands and flags.
    • Enhanced internal logic for deprecated flag and environment variable management.
  • Chores

    • Removed the deprecated commands: hclfmt, hclvalidate, and validate-inputs from the CLI.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 22, 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 22, 2025 0:17am

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 22, 2025

📝 Walkthrough

Walkthrough

This change removes the deprecated CLI commands hclfmt, hclvalidate, and validate-inputs from the codebase, replacing their usage and references with the newer unified hcl command set (hcl format, hcl validate). It updates command name constants to a consistent naming scheme, generalizes and extends the deprecated command replacement logic, and introduces a new strict control for preventing deprecated commands. The change also adds support for deprecated environment variables in relevant flags and exposes certain methods for improved accessibility. No changes were made to the core logic or behavior of the remaining commands.

Changes

File(s) Change Summary
cli/app_test.go Updated tests to use new command name constants, removed references to deleted commands, and adjusted autocomplete tests to reflect command removals and renamings.
cli/commands/commands.go Removed imports and usage of hclfmt, hclvalidate, and validateinputs commands; updated command groups accordingly.
cli/commands/deprecated.go Renamed deprecated command constants, generalized deprecated command replacement logic, added new deprecated commands, and updated execution logic to use new root command and strict controls.
cli/commands/graph/cli.go
cli/commands/run-all/cli.go
Removed imports and subcommands for hclfmt and validateinputs.
cli/commands/hcl/format/cli.go
cli/commands/hcl/validate/cli.go
Added support for deprecated environment variables in flag definitions; updated comments and formatting.
cli/commands/hclfmt/cli.go
cli/commands/hclvalidate/cli.go
cli/commands/validate-inputs/cli.go
Deleted files implementing the deprecated hclfmt, hclvalidate, and validate-inputs commands.
cli/flags/deprecated_flag.go Simplified DeprecatedFlag methods to remove fallback logic; now only return explicitly set names/env vars.
cli/flags/flag_opts.go Added WithDeprecatedEnvVars, WithDeprecatedFlagNames, and WithDeprecatedFlagName functions for more granular deprecated flag handling.
internal/cli/app.go Renamed newRootCommand to NewRootCommand (exported); updated usage accordingly.
internal/cli/args.go Added String() method to Args type for string representation.
internal/strict/controls/controls.go Added new strict control CLIRedesign to prevent use of deprecated commands.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant DeprecatedCmdHandler
    participant NewRootCmd

    User->>CLI: Run deprecated command (e.g., hclfmt)
    CLI->>DeprecatedCmdHandler: Check for deprecated command
    DeprecatedCmdHandler->>NewRootCmd: Replace with new command (e.g., hcl format)
    NewRootCmd->>CLI: Execute replacement command with original args
    CLI->>User: Output result
Loading

Possibly related PRs

Suggested reviewers

  • yhakbar
✨ 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.

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

@lev-ok lev-ok marked this pull request as ready for review April 22, 2025 12:14
@lev-ok lev-ok requested review from denis256 and yhakbar as code owners April 22, 2025 12:14
Copy link
Copy Markdown
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/strict/controls/controls.go (1)

47-48: Consider clarifying the CLIRedesign control description

The new CLIRedesign control is added correctly, but its description ("Prevents deprecated commands from being used.") is identical to the DeprecatedCommands control on line 80. This could be confusing.

Consider updating the description to better distinguish its specific purpose:

- Description: "Prevents deprecated commands from being used.",
+ Description: "Prevents deprecated commands that are being replaced as part of the CLI redesign effort.",
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 57fb6d9 and dffbc0f.

📒 Files selected for processing (15)
  • cli/app_test.go (5 hunks)
  • cli/commands/commands.go (0 hunks)
  • cli/commands/deprecated.go (2 hunks)
  • cli/commands/graph/cli.go (0 hunks)
  • cli/commands/hcl/format/cli.go (1 hunks)
  • cli/commands/hcl/validate/cli.go (2 hunks)
  • cli/commands/hclfmt/cli.go (0 hunks)
  • cli/commands/hclvalidate/cli.go (0 hunks)
  • cli/commands/run-all/cli.go (0 hunks)
  • cli/commands/validate-inputs/cli.go (0 hunks)
  • cli/flags/deprecated_flag.go (0 hunks)
  • cli/flags/flag_opts.go (1 hunks)
  • internal/cli/app.go (2 hunks)
  • internal/cli/args.go (1 hunks)
  • internal/strict/controls/controls.go (2 hunks)
💤 Files with no reviewable changes (7)
  • cli/flags/deprecated_flag.go
  • cli/commands/graph/cli.go
  • cli/commands/commands.go
  • cli/commands/hclfmt/cli.go
  • cli/commands/validate-inputs/cli.go
  • cli/commands/run-all/cli.go
  • cli/commands/hclvalidate/cli.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.

  • internal/cli/app.go
  • cli/commands/hcl/validate/cli.go
  • internal/cli/args.go
  • cli/flags/flag_opts.go
  • internal/strict/controls/controls.go
  • cli/commands/hcl/format/cli.go
  • cli/app_test.go
  • cli/commands/deprecated.go
🧬 Code Graph Analysis (3)
cli/flags/flag_opts.go (3)
cli/flags/deprecated_flag.go (2)
  • RegisterStrictControlsFunc (89-89)
  • DeprecatedFlag (18-25)
cli/flags/flag.go (1)
  • Flag (21-25)
internal/cli/flag.go (1)
  • Flag (76-98)
cli/commands/hcl/format/cli.go (3)
cli/flags/flag_opts.go (2)
  • WithDeprecatedEnvVars (156-167)
  • WithDeprecatedNames (118-130)
internal/cli/slice_flag.go (1)
  • SliceFlag (23-58)
internal/cli/bool_flag.go (1)
  • BoolFlag (13-49)
cli/app_test.go (2)
cli/commands/deprecated.go (4)
  • CommandApplyAllName (23-23)
  • CommandDestroyAllName (24-24)
  • CommandPlanAllName (22-22)
  • CommandHCLFmtName (28-28)
tf/tf.go (2)
  • CommandNameApply (15-15)
  • CommandNameDestroy (16-16)
🪛 GitHub Actions: Strict Lint
internal/cli/app.go

[error] 234-234: Function 'initialSetup' has high cognitive complexity (32 > 30) (gocognit).

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Test (macos)
  • GitHub Check: Test (windows)
  • GitHub Check: build-and-test
  • GitHub Check: Pull Request has non-contributor approval
🔇 Additional comments (21)
internal/cli/args.go (1)

29-32: LGTM: Well-implemented String() method

The addition of a String() method to the Args type is a clean implementation of the fmt.Stringer interface. This will be useful for converting argument slices to command strings, which complements the other slice manipulation methods in this type.

internal/cli/app.go (1)

167-183: Appropriately exported NewRootCommand method

Making this method public by renaming from newRootCommand to NewRootCommand follows Go's naming conventions and improves accessibility for testing or extension. The functionality remains unchanged, but now external packages can access this method directly.

cli/commands/hcl/format/cli.go (4)

33-35: LGTM: Added proper support for deprecated environment variables

The addition of deprecated environment variable support is well-implemented using the WithDeprecatedEnvVars function, with helpful comments documenting the variable names.


43-45: LGTM: Consistent implementation for excluding directories

The deprecated environment variable support is properly implemented for the exclude-dir flag, maintaining consistency with other flags.


53-55: LGTM: Proper handling for check flag deprecation

The check flag correctly supports both deprecated environment variables and flag names.


63-65: LGTM: Consistent implementation for diff flag

The diff flag's deprecated environment variables are properly configured.

cli/app_test.go (4)

287-288: Command constant naming pattern updated for consistency.

The command constants have been renamed from CommandNameApplyAll to CommandApplyAllName (and similarly for other commands) to follow a consistent naming pattern of Command<Name>Name throughout the codebase.


314-324: Command constant naming updated for consistency in test cases.

All references to command constants have been updated to follow the new naming pattern. This maintains consistency with the command constant definitions in the cli/commands/deprecated.go file.


467-471: Updated command references in tests to use constants instead of string literals.

References to the deprecated hclfmt command have been replaced with the constant CommandHCLFmtName, and similarly for plan-all command references. This improves maintainability by centralizing command naming.


576-600: Updated test command filter list to reflect CLI redesign changes.

The hclfmt and validate-inputs commands have been removed from the expected autocomplete list and replaced with hcl command as part of the CLI redesign. This ensures that autocomplete tests correctly validate the new command structure where these commands are now deprecated.

cli/commands/hcl/validate/cli.go (4)

32-38: Added support for deprecated flag names and environment variables.

Support for deprecated flags and environment variables has been added for the strict flag, with proper control mechanisms to handle the deprecation. This ensures backward compatibility while transitioning to the new CLI design.

  • Added --strict-validate as a deprecated flag name
  • Added environment variables like TG_STRICT_VALIDATE and TG_HCLVALIDATE_STRICT_VALIDATE
  • Added support for --terragrunt-strict-validate with environment variable support

The added support leverages the new strict control mechanism to properly manage the deprecation process.


52-55: Added support for deprecated environment variables for show-config-path flag.

Support for deprecated environment variables like TG_HCLVALIDATE_STRICT_VALIDATE and flag names like --terragrunt-hclvalidate-show-config-path has been added to maintain backward compatibility during transition to the new CLI design.


63-65: Added support for deprecated environment variables for json flag.

Support for deprecated environment variables like TG_HCLVALIDATE_JSON and flag names like --terragrunt-hclvalidate-json has been added, providing a smoother transition for users of the deprecated hclvalidate command.


71-80: Improved NewCommand function formatting for better readability.

The NewCommand function structure has been reformatted to improve readability without changing functionality. This makes the code more maintainable.

cli/flags/flag_opts.go (3)

155-167: Added WithDeprecatedEnvVars function for more granular control of deprecated flags.

This new function allows creating a flag with only deprecated environment variables, without having to also specify deprecated flag names. This provides more flexibility in maintaining backward compatibility through environment variables independently from flag names.


169-181: Added WithDeprecatedFlagNames function for more granular control of deprecated flags.

This function enables creating a flag with only deprecated flag names, without affecting environment variables. This complements the WithDeprecatedEnvVars function to provide a complete set of options for handling various deprecation scenarios.


183-188: Added convenience function WithDeprecatedFlagName for single flag name deprecation.

This helper function simplifies the common case of deprecating a single flag name, improving developer experience when implementing flag deprecations.

cli/commands/deprecated.go (4)

7-9: Added imports for new HCL-related command modules.

Added imports for the hcl, format, and validate packages that provide the replacement functionality for the deprecated commands. This enables the redirection of deprecated commands to their new equivalents.


18-31: Renamed and added command constants for consistency and CLI redesign.

  1. Renamed existing command constants to follow the consistent pattern Command<Name>Name (e.g., CommandSpinUpName instead of CommandNameSpinUp).
  2. Added constants for the newly deprecated commands: CommandHCLFmtName, CommandHCLValidateName, and CommandValidateInputsName.

This improves the consistency of the codebase and properly identifies the commands being deprecated as part of the CLI redesign.


36-47: Updated deprecated command replacement map to support CLI redesign.

The map of deprecated commands to their replacements has been updated to:

  1. Use the renamed command constants
  2. Use the new replaceDeprecatedCommandFunc signature
  3. Add mappings for the newly deprecated commands (hclfmt, hclvalidate, validate-inputs)
  4. Specify the appropriate strict control (CLIRedesign for the new deprecations)

This update ensures that users of deprecated commands are properly redirected to the new command structure.


52-69: Refactored the deprecated command replacement function for flexibility and strict control.

The replaceDeprecatedCommandFunc has been refactored to:

  1. Accept a strict control name and a variadic argument list instead of specific command names
  2. Construct the new command string from the argument slice
  3. Use strict control filtering with the provided control name
  4. Append original CLI arguments to the replacement command arguments
  5. Run the new root command with the combined arguments

This refactoring provides more flexibility in handling deprecated commands and better integration with the strict control system.

Comment on lines +73 to +75
flags.WithDeprecatedEnvVars(tgPrefix.EnvVars("hclfmt-diff"), terragruntPrefixControl), // `TG_HCLFMT_STDIN`
flags.WithDeprecatedNames(terragruntPrefix.FlagNames("hclfmt-stdin"), terragruntPrefixControl), // `--terragrunt-hclfmt-stdin`, `TERRAGRUNT_HCLFMT_STDIN`
),
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot Apr 22, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix incorrect environment variable name for stdin flag

There's an error in the environment variable name for the stdin flag: it's using "hclfmt-diff" instead of "hclfmt-stdin".

Apply this correction:

- flags.WithDeprecatedEnvVars(tgPrefix.EnvVars("hclfmt-diff"), terragruntPrefixControl),          // `TG_HCLFMT_STDIN`
+ flags.WithDeprecatedEnvVars(tgPrefix.EnvVars("hclfmt-stdin"), terragruntPrefixControl),         // `TG_HCLFMT_STDIN`
📝 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
flags.WithDeprecatedEnvVars(tgPrefix.EnvVars("hclfmt-diff"), terragruntPrefixControl), // `TG_HCLFMT_STDIN`
flags.WithDeprecatedNames(terragruntPrefix.FlagNames("hclfmt-stdin"), terragruntPrefixControl), // `--terragrunt-hclfmt-stdin`, `TERRAGRUNT_HCLFMT_STDIN`
),
flags.WithDeprecatedEnvVars(tgPrefix.EnvVars("hclfmt-stdin"), terragruntPrefixControl), // `TG_HCLFMT_STDIN`
flags.WithDeprecatedNames(terragruntPrefix.FlagNames("hclfmt-stdin"), terragruntPrefixControl), // `--terragrunt-hclfmt-stdin`, `TERRAGRUNT_HCLFMT_STDIN`
),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you my friend. You are the best!

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.

@levkohimins You're welcome! Glad I could help. Always happy to spot these small details to ensure everything works correctly. Let me know if you need any other assistance with your PR.

// RequireExplicitBootstrap is the control that prevents the backend for remote state from being bootstrapped unless the `--backend-bootstrap` flag is specified.
RequireExplicitBootstrap = "require-explicit-bootstrap"

// CLIRedesign is the control that prevents the use of deprecated commands.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// CLIRedesign is the control that prevents the use of deprecated commands.
// CLIRedesign is the control that prevents the use of commands deprecated as part of the CLI Redesign.

NIT: Please address this in a different PR.

requireExplicitBootstrapControl,
&Control{
Name: CLIRedesign,
Description: "Prevents deprecated commands from being used.",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Description: "Prevents deprecated commands from being used.",
Description: "Prevents the use of commands deprecated as part of the CLI Redesign."

NIT: Please address this in a different PR.

Copy link
Copy Markdown
Collaborator

@yhakbar yhakbar left a comment

Choose a reason for hiding this comment

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

:shipit:

@lev-ok lev-ok merged commit 6af6da5 into main Apr 22, 2025
19 of 22 checks passed
@lev-ok lev-ok deleted the feat/strict-control-deprecated-hcl-commands branch April 22, 2025 13:45
@coderabbitai coderabbitai bot mentioned this pull request Oct 7, 2025
6 tasks
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.

3 participants