chore: hclfmt hclvalidate validate-inputs as deprecated commands#4196
chore: hclfmt hclvalidate validate-inputs as deprecated commands#4196
hclfmt hclvalidate validate-inputs as deprecated commands#4196Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
📝 WalkthroughWalkthroughThis change removes the deprecated CLI commands Changes
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
Possibly related PRs
Suggested reviewers
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/strict/controls/controls.go (1)
47-48: Consider clarifying the CLIRedesign control descriptionThe 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
📒 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.gocli/commands/hcl/validate/cli.gointernal/cli/args.gocli/flags/flag_opts.gointernal/strict/controls/controls.gocli/commands/hcl/format/cli.gocli/app_test.gocli/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() methodThe 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 methodMaking 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 variablesThe 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 directoriesThe 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 deprecationThe check flag correctly supports both deprecated environment variables and flag names.
63-65: LGTM: Consistent implementation for diff flagThe 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
CommandNameApplyAlltoCommandApplyAllName(and similarly for other commands) to follow a consistent naming pattern ofCommand<Name>Namethroughout 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.gofile.
467-471: Updated command references in tests to use constants instead of string literals.References to the deprecated
hclfmtcommand have been replaced with the constantCommandHCLFmtName, 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
hclfmtandvalidate-inputscommands have been removed from the expected autocomplete list and replaced withhclcommand 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
strictflag, with proper control mechanisms to handle the deprecation. This ensures backward compatibility while transitioning to the new CLI design.
- Added
--strict-validateas a deprecated flag name- Added environment variables like
TG_STRICT_VALIDATEandTG_HCLVALIDATE_STRICT_VALIDATE- Added support for
--terragrunt-strict-validatewith environment variable supportThe added support leverages the new strict control mechanism to properly manage the deprecation process.
52-55: Added support for deprecated environment variables forshow-config-pathflag.Support for deprecated environment variables like
TG_HCLVALIDATE_STRICT_VALIDATEand flag names like--terragrunt-hclvalidate-show-config-pathhas been added to maintain backward compatibility during transition to the new CLI design.
63-65: Added support for deprecated environment variables forjsonflag.Support for deprecated environment variables like
TG_HCLVALIDATE_JSONand flag names like--terragrunt-hclvalidate-jsonhas been added, providing a smoother transition for users of the deprecatedhclvalidatecommand.
71-80: ImprovedNewCommandfunction formatting for better readability.The
NewCommandfunction structure has been reformatted to improve readability without changing functionality. This makes the code more maintainable.cli/flags/flag_opts.go (3)
155-167: AddedWithDeprecatedEnvVarsfunction 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: AddedWithDeprecatedFlagNamesfunction 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
WithDeprecatedEnvVarsfunction to provide a complete set of options for handling various deprecation scenarios.
183-188: Added convenience functionWithDeprecatedFlagNamefor 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, andvalidatepackages 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.
- Renamed existing command constants to follow the consistent pattern
Command<Name>Name(e.g.,CommandSpinUpNameinstead ofCommandNameSpinUp).- Added constants for the newly deprecated commands:
CommandHCLFmtName,CommandHCLValidateName, andCommandValidateInputsName.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:
- Use the renamed command constants
- Use the new
replaceDeprecatedCommandFuncsignature- Add mappings for the newly deprecated commands (
hclfmt,hclvalidate,validate-inputs)- Specify the appropriate strict control (
CLIRedesignfor 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
replaceDeprecatedCommandFunchas been refactored to:
- Accept a strict control name and a variadic argument list instead of specific command names
- Construct the new command string from the argument slice
- Use strict control filtering with the provided control name
- Append original CLI arguments to the replacement command arguments
- 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.
| flags.WithDeprecatedEnvVars(tgPrefix.EnvVars("hclfmt-diff"), terragruntPrefixControl), // `TG_HCLFMT_STDIN` | ||
| flags.WithDeprecatedNames(terragruntPrefix.FlagNames("hclfmt-stdin"), terragruntPrefixControl), // `--terragrunt-hclfmt-stdin`, `TERRAGRUNT_HCLFMT_STDIN` | ||
| ), |
There was a problem hiding this comment.
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.
| 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` | |
| ), |
There was a problem hiding this comment.
Thank you my friend. You are the best!
There was a problem hiding this comment.
@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. |
There was a problem hiding this comment.
| // 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.", |
There was a problem hiding this comment.
| 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.
Description
Adding
hclfmthclvalidatevalidate-inputscommands under strictcli-redesigncontrol.TODOs
Read the Gruntwork contribution guidelines.
Release Notes (draft)
Added / Removed / Updated [X].
Migration Guide
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Chores
hclfmt,hclvalidate, andvalidate-inputsfrom the CLI.