-
Notifications
You must be signed in to change notification settings - Fork 345
Add buf source edit deprecate command #4306
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
base: main
Are you sure you want to change the base?
Conversation
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.
|
The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).
|
| errorFormatFlagName = "error-format" | ||
| excludePathsFlagName = "exclude-path" | ||
| pathsFlagName = "path" | ||
| nameFlagName = "name" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| diffBuffer := bytes.NewBuffer(nil) | ||
| changedPaths, err := storage.DiffWithFilenames( | ||
| ctx, | ||
| diffBuffer, | ||
| originalReadBucket, | ||
| formattedReadBucket, | ||
| storage.DiffWithExternalPaths(), | ||
| ) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| diffExists := diffBuffer.Len() > 0 | ||
|
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Adds a new
buf source edit deprecatecommand that edits Protobuf source files in-place. The command supports--nameflags that addsoption deprecated = true;to types matching the FQN prefix.