enumer
enumer copied to clipboard
Add transform to MACRO_CASE and phrase
Added support for transforming to MACRO_CASE and phrase.
1. phrase
We have a concrete use-case for phrase
, which is using enumer
to generate errors:
//go:generate enumer -type=ErrorCode -transform=phrase --trimprefix=Err
type ErrorCode int
func (e ErrorCode) Error() string {
return e.String()
}
const (
ErrInsufficientBalance ErrorCode = iota
ErrInvalidNumberOfArguments
)
This means we can directly use these error constants as a normal error i.e.
ErrInvalidNumberOfArguments.Error() == "invalid number of arguments"
2. macro
MACRO_CASE as it's the most wide-spread form of defining constants (JS/Node, Ruby, Python, Bash) and makes sense for us as this is how we define them on our React front-end.
Shameless bump
Shameless re-bump
Is this met for you by @niktri's fork, Enumerx
, release v1.1.5 ?
https://github.com/niktri/enumerx/commit/712e0f2655c1d8b4ba84712606e4cf74ad641c50
(transform=snake_upper
)
To be honest I've been using my own fork that this PR is coming from: https://github.com/abeMedia/enumer Would love to get this merged though!