Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@emcfarlane
Copy link
Contributor

Adds a new buf source edit deprecate command that edits Protobuf source files in-place. The command supports --name flags that adds option deprecated = true; to types matching the FQN prefix.

Adds a new `buf source edit deprecate` command that edits Protobuf
source files in-place. The command supports `--name` flags that
adds `option deprecated = true;` to types matching the FQN prefix.
@github-actions
Copy link
Contributor

github-actions bot commented Jan 26, 2026

The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedJan 28, 2026, 5:16 PM

errorFormatFlagName = "error-format"
excludePathsFlagName = "exclude-path"
pathsFlagName = "path"
nameFlagName = "name"
Copy link
Member

Choose a reason for hiding this comment

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

Should we call this flag "prefix" instead? It can be an exact match to a name or a prefix, right?

Copy link
Member

Choose a reason for hiding this comment

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

prefix is probably more correct, although it does end up being more to type :).

Are we expecting in the future to add different flags to this command, like --file=<name> to deprecate a file? I guess I'm wondering if this ought to be a flag at all, and not just a positional arg?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to prefix. I think it's preferred to have a flag with the one arg being the input.

Copy link
Member

Choose a reason for hiding this comment

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

ah right, I keep forgetting about the <source> arg. ignore me.

Comment on lines 208 to 220
diffBuffer := bytes.NewBuffer(nil)
changedPaths, err := storage.DiffWithFilenames(
ctx,
diffBuffer,
originalReadBucket,
formattedReadBucket,
storage.DiffWithExternalPaths(),
)
if err != nil {
return err
}
diffExists := diffBuffer.Len() > 0

Copy link
Member

Choose a reason for hiding this comment

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

We should only bother doing the work of calculating the diff if flags.Diff {...} -- unlike format, we are not looking to return an error code based on the diff existing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use it for avoiding writes, getting the changedPaths, changed diff to output to io.Discard if not using it.

will have the 'deprecated = true' option added. For fields and enum values, only
exact matches are deprecated.

By default, the source is the current directory and files are formatted and rewritten in-place.
Copy link
Member

Choose a reason for hiding this comment

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

The UX of this command as it currently stands is that even if nothing is deprecated (either they're already deprecated or there are no matches), this will always format the file. I'm undecided whether or not this is desirable... I think it's fine? In which case, related to my comment on the diff, maybe we do want to handle some kind of exit code when any diff exists.

Copy link
Member

Choose a reason for hiding this comment

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

I guess my vague notion would be that we ought to not format anything if we don't match, and perhaps even return an exit code of 1, in the same vein of doing an rg <match> that doesn't match anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a doc comment about the error handling. We now error if no provided prefix matches. If prefix match but already deprecated/format command succeeds. If prefix match but not formatted, still formats.

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.

4 participants