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

Add dict_replace_if_equal command to buildozer. #1274

Merged
merged 3 commits into from
Jun 26, 2024

Conversation

tsell
Copy link
Contributor

@tsell tsell commented May 31, 2024

This is useful for making modifications at scale, where you only want to replace certain dictionary values. To illustrate, suppose you have a BUILD file containing many targets, some of which use some "old_value" which you wish to replace with "new_value" in a dictionary, and some of which use other values that you don't want to modify:

macro(
  name = "foo",
  macro_values = {
    "key": "old_value",
  },
)

macro(
  name = "bar",
  macro_values = {
    "key": "neutral_value",
  },
)

With this new command, these can all be modified like so:

buildozer "dict_replace_if_equal macro_values key old_value new_value" //path/to/these/targets:*

Resulting in the desired change:

macro(
  name = "foo",
  macro_values = {
    "key": "new_value",
  },
)

macro(
  name = "bar",
  macro_values = {
    "key": "neutral_value",
  },
)

Copy link
Member

@vladmos vladmos left a comment

Choose a reason for hiding this comment

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

Thanks!

edit/buildozer.go Outdated Show resolved Hide resolved
edit/buildozer_test.go Outdated Show resolved Hide resolved
Copy link
Contributor Author

@tsell tsell left a comment

Choose a reason for hiding this comment

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

Done

@tsell tsell requested a review from vladmos June 7, 2024 20:55
@vladmos vladmos merged commit 9b954d0 into bazelbuild:master Jun 26, 2024
2 checks passed
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.

2 participants