commands/init: Make validation of positional arguments happen in the arguments package. Refactor away unneeded code.#38692
Open
SarahFrench wants to merge 3 commits into
Open
Conversation
…onal arguments. This replaces validation performed by the `ModulePath` function.
There are no valid args to be passed around in the Args field. Now that validation of unexpected positional arguments is in place earlier this field is useless.
…leDir() `ModulePath` is being used as a fancy/indirect way to use `os.Getwd`, and the data in (Meta).WorkingDir is equivalent to that. When a command is run in the full CLI the (Meta).WorkingDir value is set to the current working dir (which may have been changed by a -chdir flag).
arguments package. Refactor away unneeded code.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR refactors how unexpected positional arguments supplied to the
initcommand are validated.The
ModulePathfunction is the result of how commands used to have positional DIR arguments, which allowed users to use a directory other than the directory where the CLI was being used. When that DIR argument was replaced with the -chdir flag, we end up with the code below. Whereas before it would use that argument to determine the path to the root module, now it just validates that the DIR argument isn't mistakenly being used and then returns details about the current working directory:terraform/internal/command/command.go
Lines 62 to 75 in 78a3330
It doesn't make sense to validate unexpected positional arguments here; that should be done in the
argumentspackage.This PR updates the code for parsing flags and arguments used with the
initcommand to assert that no positional arguments are expected. If that validation passes, there are no args, then we don't need to return an empty list of args to the command implementation through theArgsfield removed in this PR.Now that no args are being passed into the
ModulePathfunction it's just a fancy way of calling os.Getwd. The Meta contains details about the working directory, so I've replaced use of theModulePathfunction with the relevant method.This is work towards deleting the
ModulePathfunction from the codebase 💪🏻Target Release
1.16.x
Rollback Plan
Changes to Security Controls
Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.
CHANGELOG entry