feat: add RegisterIntEnum for integer-based enum flags#116
Merged
Conversation
2b45f54 to
e26e099
Compare
RegisterIntEnum for integer-based enum flags
e26e099 to
f90cb75
Compare
Add DefineIntEnumHookFunc and StringToIntEnumHookFunc for integer-based enum types using enumflag/v2. Widen enumHelpText constraint to cover all integer widths (~int through ~int64). Include unit tests for both hook factories. Co-authored-by: Ona <no-reply@ona.com>
RegisterIntEnum[E] eliminates boilerplate for integer enum types by auto-registering define, decode, and completion hooks via enumflag/v2. Mirrors RegisterEnum[E ~string] but targets ~int through ~int64. Include integration tests covering define+unmarshal, aliases, case-insensitivity, validation, defaults, auto-completion, JSON schema, duplicate detection, and description enhancement. Co-authored-by: Ona <no-reply@ona.com>
- Fix broken doc comments: reorder RegisterEnum before RegisterIntEnum so each has its own doc block (2.1) - Add alias collision panic to StringToIntEnumHookFunc (2.2) - Add env-var and env-only integration tests for RegisterIntEnum (2.3) - Validate empty/nil values map in RegisterIntEnum (2.7) - Document int enum ordering by integer value (3.1) - Document unsigned type exclusion (3.3) - Fix enumHelpText int truncation on 32-bit: use int64 (3.2) Co-authored-by: Ona <no-reply@ona.com>
f90cb75 to
de06cbd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
RegisterIntEnum[E ~int | ~int8 | ~int16 | ~int32 | ~int64]registers an integer-based enum type for automatic flag handling viaenumflag/v2. MirrorsRegisterEnum[E ~string](#115) but targets signed integer enum types.After registration, struct fields of type
Ework withoutflagcustom:"true"or manualDefine/Decode/Completehook methods.Unsigned integer types are not supported (documented in the doc comment).
Usage
Features
enumflag/v2){val1,val2,...}description enhancement (sorted by integer value)EnumValuerflagsflagenv:"true",flagenv:"only",flagrequired:"true",default:"..."Commits
feat(internal/hooks):DefineIntEnumHookFuncandStringToIntEnumHookFunc— define/decode hook factories for integer enums usingenumflag/v2. WidensenumHelpTextconstraint to cover all integer widths.feat:PublicRegisterIntEnum+ integration tests.fix:Address review findings — fix broken doc comments (2.1), add alias collision panic toStringToIntEnumHookFunc(2.2), add env-var/env-only tests (2.3), validate empty values (2.7), document ordering/unsigned exclusion (3.1/3.3), fixenumHelpTextint64 truncation on 32-bit (3.2).How to test