@@ -31,7 +31,7 @@ import (
3131// However, applications don't need to base their own enum types on Flag. The
3232// only requirement for user-defined enumeration flags is that they must be
3333// (“somewhat”) compatible with the Flag type, or more precise: user-defined
34- // enumerations must satisfy [constraints.Integer ].
34+ // enumerations must satisfy [constraints.Ordered ].
3535type Flag uint
3636
3737// EnumCaseSensitivity specifies whether the textual representations of enum
@@ -46,11 +46,11 @@ const (
4646)
4747
4848// EnumFlagValue wraps a user-defined enum type value satisfying
49- // [constraints.Integer ] or [][constraints.Integer ]. It implements the
49+ // [constraints.Ordered ] or [][constraints.Ordered ]. It implements the
5050// [github.com/spf13/pflag.Value] interface, so the user-defined enum type value
5151// can directly be used with the fine pflag drop-in package for Golang CLI
5252// flags.
53- type EnumFlagValue [E constraints.Integer ] struct {
53+ type EnumFlagValue [E constraints.Ordered ] struct {
5454 value enumValue [E ] // enum value of a user-defined enum scalar or slice type.
5555 enumtype string // user-friendly name of the user-defined enum type.
5656 names enumMapper [E ] // enum value names.
@@ -63,26 +63,26 @@ type EnumFlagValue[E constraints.Integer] struct {
6363// code”: by just moving the interface type from the source file with the struct
6464// types to the source file with the consumer we achieve immediate Go
6565// perfectness! Strike!
66- type enumValue [E constraints.Integer ] interface {
66+ type enumValue [E constraints.Ordered ] interface {
6767 Get () any
6868 Set (val string , names enumMapper [E ]) error
6969 String (names enumMapper [E ]) string
7070 NewCompletor (enums EnumIdentifiers [E ], help Help [E ]) Completor
7171}
7272
73- // New wraps a given enum variable (satisfying [constraints.Integer ]) so that it
73+ // New wraps a given enum variable (satisfying [constraints.Ordered ]) so that it
7474// can be used as a flag Value with [github.com/spf13/pflag.Var] and
7575// [github.com/spf13/pflag.VarP]. In case no default enum value should be set
7676// and therefore no default shown in [spf13/cobra], use [NewWithoutDefault]
7777// instead.
7878//
7979// [spf13/cobra]: https://github.com/spf13/cobra
80- func New [E constraints.Integer ](flag * E , typename string , mapping EnumIdentifiers [E ], sensitivity EnumCaseSensitivity ) * EnumFlagValue [E ] {
80+ func New [E constraints.Ordered ](flag * E , typename string , mapping EnumIdentifiers [E ], sensitivity EnumCaseSensitivity ) * EnumFlagValue [E ] {
8181 return new ("New ", flag , typename , mapping , sensitivity , false )
8282}
8383
8484// NewWithoutDefault wraps a given enum variable (satisfying
85- // [constraints.Integer ]) so that it can be used as a flag Value with
85+ // [constraints.Ordered ]) so that it can be used as a flag Value with
8686// [github.com/spf13/pflag.Var] and [github.com/spf13/pflag.VarP]. Please note
8787// that the zero enum value must not be mapped and thus not be assigned to any
8888// enum value textual representation.
@@ -91,14 +91,14 @@ func New[E constraints.Integer](flag *E, typename string, mapping EnumIdentifier
9191// created with NewWithoutDefault.
9292//
9393// [spf13/cobra]: https://github.com/spf13/cobra
94- func NewWithoutDefault [E constraints.Integer ](flag * E , typename string , mapping EnumIdentifiers [E ], sensitivity EnumCaseSensitivity ) * EnumFlagValue [E ] {
94+ func NewWithoutDefault [E constraints.Ordered ](flag * E , typename string , mapping EnumIdentifiers [E ], sensitivity EnumCaseSensitivity ) * EnumFlagValue [E ] {
9595 return new ("NewWithoutDefault ", flag , typename , mapping , sensitivity , true )
9696}
9797
9898// new returns a new enum variable to be used with pflag.Var and pflag.VarP.
99- func new [E constraints.Integer ](ctor string , flag * E , typename string , mapping EnumIdentifiers [E ], sensitivity EnumCaseSensitivity , nodefault bool ) * EnumFlagValue [E ] {
99+ func new [E constraints.Ordered ](ctor string , flag * E , typename string , mapping EnumIdentifiers [E ], sensitivity EnumCaseSensitivity , nodefault bool ) * EnumFlagValue [E ] {
100100 if flag == nil {
101- panic (fmt .Sprintf ("%s requires flag to be a non-nil pointer to an enum value satisfying constraints.Integer " , ctor ))
101+ panic (fmt .Sprintf ("%s requires flag to be a non-nil pointer to an enum value satisfying constraints.Ordered " , ctor ))
102102 }
103103 if mapping == nil {
104104 panic (fmt .Sprintf ("%s requires mapping not to be nil" , ctor ))
@@ -110,12 +110,12 @@ func new[E constraints.Integer](ctor string, flag *E, typename string, mapping E
110110 }
111111}
112112
113- // NewSlice wraps a given enum slice variable (satisfying [constraints.Integer ])
113+ // NewSlice wraps a given enum slice variable (satisfying [constraints.Ordered ])
114114// so that it can be used as a flag Value with [github.com/spf13/pflag.Var] and
115115// [github.com/spf13/pflag.VarP].
116- func NewSlice [E constraints.Integer ](flag * []E , typename string , mapping EnumIdentifiers [E ], sensitivity EnumCaseSensitivity ) * EnumFlagValue [E ] {
116+ func NewSlice [E constraints.Ordered ](flag * []E , typename string , mapping EnumIdentifiers [E ], sensitivity EnumCaseSensitivity ) * EnumFlagValue [E ] {
117117 if flag == nil {
118- panic ("NewSlice requires flag to be a non-nil pointer to an enum value slice satisfying []constraints.Integer " )
118+ panic ("NewSlice requires flag to be a non-nil pointer to an enum value slice satisfying []any " )
119119 }
120120 if mapping == nil {
121121 panic ("NewSlice requires mapping not to be nil" )
0 commit comments