Closed akutz closed 2 months ago
Thanks @akutz , very nice. This would also be quite useful within govmomi, we can replace this: https://github.com/vmware/govmomi/blob/main/simulator/guest_id.sh#L29
And lists of enum consts are sprinkled all over govc, e.g.
I have replaced the aforementioned guest_id.sh
with the new work.
Hey @dougm, it needs another review. Please see the updates I made to it to make it a little more useful.
Description
This patch ensures enum types are generated with Values functions that make it trivial to discover all values for a given enum.
@dougm, I am not sure if this is something we want or not. I propose it to make it simpler for projects like VM Operator to generate a list of all constant values for enums like GuestOSID. I checked, and while it is possible to use unsafe code to list all types in a given package, Go's compiler makes it impossible to list all exported constants at the package level. Other than AST with source analysis, this is the only way for a downstream project to get a list of all an "enum"'s values. The question is -- is it worth the increase in memory?
cc @dilyar85 as I was doing this so you could create a
pkg/gen/guestosids/guestosids.go
file in VM Operator that is effectively amain.go
and could be used with//go:generate
in the./api/v1alpha3/virtualmachine_types.go
file to automatically generate a type with the correct kubebuilder comments for an enum.Closes:
NA
Type of change
Please mark options that are relevant:
How Has This Been Tested?
NA
Checklist:
CONTRIBUTION
guidelines of this project