[go: up one dir, main page]

Skip to content
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

cli: Remove legacy positional path arguments #27664

Merged
merged 2 commits into from
Feb 2, 2021

Conversation

alisdair
Copy link
Contributor
@alisdair alisdair commented Feb 2, 2021

Several commands continued to support the legacy positional path argument to specify a working directory. This functionality has been replaced with the global -chdir flag (#26087), which is specified before any other arguments, including the sub-command name.

This commit removes support for the trailing path parameter from most commands. The only command which still supports a path argument is fmt, which also supports "-" to indicate receiving configuration from standard input.

Any invocation of a command with an invalid trailing path parameter will result in a short error message, pointing at the -chdir alternative.

There are many test updates in this commit, almost all of which are migrations from using positional arguments to specify a working directory. Because of the layer at which these tests run, we are unable to use the -chdir argument, so the churn in test files is larger than ideal. Sorry!

@alisdair alisdair requested a review from a team February 2, 2021 17:09
@alisdair alisdair self-assigned this Feb 2, 2021
@codecov
Copy link
codecov bot commented Feb 2, 2021

Codecov Report

Merging #27664 (888f36a) into master (9c16e57) will decrease coverage by 0.07%.
The diff coverage is 52.08%.

Impacted Files Coverage Δ
command/console.go 32.35% <0.00%> (+0.62%) ⬆️
command/plan.go 41.66% <0.00%> (-0.30%) ⬇️
command/refresh.go 35.22% <0.00%> (ø)
command/workspace_delete.go 48.14% <0.00%> (ø)
command/workspace_list.go 46.93% <0.00%> (ø)
command/workspace_new.go 36.89% <0.00%> (ø)
command/workspace_select.go 39.18% <0.00%> (ø)
command/graph.go 45.68% <46.15%> (+1.44%) ⬆️
command/command.go 66.66% <66.66%> (-8.34%) ⬇️
command/unlock.go 34.66% <66.66%> (ø)
... and 10 more

Copy link
Contributor
@apparentlymart apparentlymart left a comment

Choose a reason for hiding this comment

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

I read though this as thoroughly as I could, although of course with this sort of systematic updating it's easy to get lost in the patterns and miss details, so I tried to look particularly carefully at the test cases just to see if they agreed with what I'd expect the new behavior to be, and they do seem to.

My sense is that it's better to get this in earlier rather than latter so that it has some time to soak in at least one alpha and then the betas, since then there's more chance of us or someone else exercising these things indirectly as part of testing something else.


Noting that we still have some commands other than terraform apply which take a plan file as a positional argument, I had a further idea here although I'm just noting it for completeness and not intending to try to increase the scope of this PR:

While terraform apply tfplan has nice ergonomics because the plan file is obviously the "direct object" of the "apply" verb, the positional form for other commands has always felt less clear to me. Given that we're already making some breaking changes here anyway, perhaps a further PR could go further by replacing those plan file position arguments with named arguments instead, like this:

terraform graph -plan=tfplan

This would avoid relying on the plan file having a meaningful name in order for the meaning of that argument to be clear, and also just generally standardize that we typically use named arguments because they are better for allowing backward-compatible additions in future. (with terraform apply tfplan of course remaining one special exception, justified due to its prominence in the CLI workflow.)

@alisdair alisdair force-pushed the alisdair/remove-positional-path-arguments branch from 3d95f7e to 9a00767 Compare February 2, 2021 18:12
Several commands continued to support the legacy positional path
argument to specify a working directory. This functionality has been
replaced with the global -chdir flag, which is specified before any
other arguments, including the sub-command name.

This commit removes support for the trailing path parameter from
most commands. The only command which still supports a path argument is
fmt, which also supports "-" to indicate receiving configuration from
standard input.

Any invocation of a command with an invalid trailing path parameter will
result in a short error message, pointing at the -chdir alternative.

There are many test updates in this commit, almost all of which are
migrations from using positional arguments to specify a working
directory. Because of the layer at which these tests run, we are unable
to use the -chdir argument, so the churn in test files is larger than
ideal. Sorry!
To make the command arguments easier to understand and extend, we are
moving away from positional arguments. This commit changes the graph
command to take a `-plan` flag instead of an optional trailing path.
@alisdair alisdair force-pushed the alisdair/remove-positional-path-arguments branch from 9a00767 to 888f36a Compare February 2, 2021 18:21
@alisdair
Copy link
Contributor Author
alisdair commented Feb 2, 2021

Thanks for the review! Your suggestion makes sense to me, so I updated the graph arguments in 888f36a. The only other command that I can find which optionally takes a plan file is show, and its arguments are much more complex, so I'd like to leave any changes to a separate proposal & PR.

@ghost
Copy link
ghost commented Mar 5, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked as resolved and limited conversation to collaborators Mar 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants