| ... | @@ -94,6 +94,8 @@ pub const Builder = struct { | ... | @@ -94,6 +94,8 @@ pub const Builder = struct { |
| 94 | name: []const u8, | 94 | name: []const u8, |
| 95 | type_id: TypeId, | 95 | type_id: TypeId, |
| 96 | description: []const u8, | 96 | description: []const u8, |
| | 97 | /// If the `type_id` is `enum` this provides the list of enum options |
| | 98 | enum_options: ?[]const []const u8, |
| 97 | }; | 99 | }; |
| 98 | | 100 | |
| 99 | const UserInputOption = struct { | 101 | const UserInputOption = struct { |
| ... | @@ -482,10 +484,21 @@ pub const Builder = struct { | ... | @@ -482,10 +484,21 @@ pub const Builder = struct { |
| 482 | const name = self.dupe(name_raw); | 484 | const name = self.dupe(name_raw); |
| 483 | const description = self.dupe(description_raw); | 485 | const description = self.dupe(description_raw); |
| 484 | const type_id = comptime typeToEnum(T); | 486 | const type_id = comptime typeToEnum(T); |
| | 487 | const enum_options = if (type_id == .@"enum") blk: { |
| | 488 | const fields = comptime std.meta.fields(T); |
| | 489 | var options = ArrayList([]const u8).initCapacity(self.allocator, fields.len) catch unreachable; |
| | 490 | |
| | 491 | inline for (fields) |field| { |
| | 492 | options.appendAssumeCapacity(field.name); |
| | 493 | } |
| | 494 | |
| | 495 | break :blk options.toOwnedSlice(); |
| | 496 | } else null; |
| 485 | const available_option = AvailableOption{ | 497 | const available_option = AvailableOption{ |
| 486 | .name = name, | 498 | .name = name, |
| 487 | .type_id = type_id, | 499 | .type_id = type_id, |
| 488 | .description = description, | 500 | .description = description, |
| | 501 | .enum_options = enum_options, |
| 489 | }; | 502 | }; |
| 490 | if ((self.available_options_map.fetchPut(name, available_option) catch unreachable) != null) { | 503 | if ((self.available_options_map.fetchPut(name, available_option) catch unreachable) != null) { |
| 491 | panic("Option '{s}' declared twice", .{name}); | 504 | panic("Option '{s}' declared twice", .{name}); |