Closed dereuromark closed 8 months ago
Given the description I think --backed=string|int
should suffice as option.
$ bin/cake bake enum FooBar -h
Bake (backed) enums for use in models.
Usage:
cake bake enum [options]
Options:
--backed, -b If using backed enums. Set to `string` or `int`.
--connection, -c The datasource connection to get data from.
In a 2nd step we could think of allowing argument/option to dictate the enum values, similar to bake migrations etc:
Backed int
0: inactive, 1:active, ...
Backed string
nope: inactive, 'yep yep':active, ...
Default
inactive, active, ...
In a 3rd step: If those would be part of the db field comment, it could be used to auto-generate the whole enum based on that, making it super RAD.
Looks like we can bake enums now for xmas:)
Given that we only now have backed, and string vs int
Couldnt we just add boolean --int
flag? -b ...
seems not necessary in that case.
--int
has just 1 character less than -b int
:)
I would prefer if we keep the more descriptive name.
Should it be just type
/t
though? Since it is clear it is a backing type on backed enums :)
I can live with type
if others are in favor.
Never mind, t is theme :)
That said: Shouldnt it throw an error if you define a short twice?
--theme, -t The theme to use when baking code. (choices:
Bake|BootstrapUI|Migrations|Queue|Search|Setup|StateMachine)
--type, -t The return type for the backed enum class
No error here..
Shouldnt it throw an error if you define a short twice?
Guess we are missing duplicate naming checks.
@ADmad it is now simpler, only one char for int
So all good?
or
Next step could be to use conventions to auto map/detect enums for table fields:
{EntityName}{FieldName}
enumE.g.
Users
table with fieldstatus
:User
entity andUserStatus
enum would map and get added to forms etc.the fails are unrelated and will be green once https://github.com/cakephp/cakephp/pull/17482 is released with 5.0.4