alvaroloes / enumer

A Go tool to auto generate methods for your enums
Other
480 stars 111 forks source link

Add comment support + temporary file before writing #33

Closed dterei closed 5 years ago

dterei commented 6 years ago

Few improvements needed by our use of stringer:

  1. Add support for including comments. We use this to mark the code as generated code on review tools like phabricator (enumer -type Day -comment @ -comment generated). The multi-flag support is needed so that the @generated tag can be split up as otherwise phabricator thinks the file calling enumber (using go generate) is generated code. Yes, dumb, but the limits of phabricator sadly.

  2. Write to a temporary file first then rename to ensure atomic operations. This prevents any issues that occur if building and generation overlap with parallel builds. E.g., we checkin the generated code to git which is common, but also generate the code again when building, which should be a noop, but can cause issues if we try to parallelize things as building may see a partial file state.

dterei commented 5 years ago

@alvaroloes ping?

dmarkham commented 5 years ago

I have merged this in my new and supported version that is a drop in replacement. A long with go mod support. If your interested. https://github.com/dmarkham/enumer

alvaroloes commented 5 years ago

Sorry for my looooong time missing. I was completely immersed in other stuff. I love this PR. Thank you very much!

dmarkham commented 5 years ago

@alvaroloes welcome back. With this merge there was a small edge case bug that was reported and fixed. Please consider this patch. Rename does not work so well across file systems so making the temporary file far away form the final place was failing for some.

https://github.com/dmarkham/enumer/commit/ceea85