| ... | ... | @@ -94,6 +94,8 @@ pub const Builder = struct { |
| 94 | 94 | name: []const u8, |
| 95 | 95 | type_id: TypeId, |
| 96 | 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 | 101 | const UserInputOption = struct { |
| ... | ... | @@ -482,10 +484,21 @@ pub const Builder = struct { |
| 482 | 484 | const name = self.dupe(name_raw); |
| 483 | 485 | const description = self.dupe(description_raw); |
| 484 | 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 | 497 | const available_option = AvailableOption{ |
| 486 | 498 | .name = name, |
| 487 | 499 | .type_id = type_id, |
| 488 | 500 | .description = description, |
| 501 | .enum_options = enum_options, |
| 489 | 502 | }; |
| 490 | 503 | if ((self.available_options_map.fetchPut(name, available_option) catch unreachable) != null) { |
| 491 | 504 | panic("Option '{s}' declared twice", .{name}); |