mirror of
https://github.com/ziglang/zig.git
synced 2024-11-15 00:26:57 +00:00
Print enum values for build options in help output (#9650)
This commit is contained in:
parent
cf75cad899
commit
ede47d49eb
@ -94,6 +94,8 @@ pub const Builder = struct {
|
||||
name: []const u8,
|
||||
type_id: TypeId,
|
||||
description: []const u8,
|
||||
/// If the `type_id` is `enum` this provides the list of enum options
|
||||
enum_options: ?[]const []const u8,
|
||||
};
|
||||
|
||||
const UserInputOption = struct {
|
||||
@ -482,10 +484,21 @@ pub const Builder = struct {
|
||||
const name = self.dupe(name_raw);
|
||||
const description = self.dupe(description_raw);
|
||||
const type_id = comptime typeToEnum(T);
|
||||
const enum_options = if (type_id == .@"enum") blk: {
|
||||
const fields = comptime std.meta.fields(T);
|
||||
var options = ArrayList([]const u8).initCapacity(self.allocator, fields.len) catch unreachable;
|
||||
|
||||
inline for (fields) |field| {
|
||||
options.appendAssumeCapacity(field.name);
|
||||
}
|
||||
|
||||
break :blk options.toOwnedSlice();
|
||||
} else null;
|
||||
const available_option = AvailableOption{
|
||||
.name = name,
|
||||
.type_id = type_id,
|
||||
.description = description,
|
||||
.enum_options = enum_options,
|
||||
};
|
||||
if ((self.available_options_map.fetchPut(name, available_option) catch unreachable) != null) {
|
||||
panic("Option '{s}' declared twice", .{name});
|
||||
|
@ -245,6 +245,13 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void
|
||||
});
|
||||
defer allocator.free(name);
|
||||
try out_stream.print("{s:<30} {s}\n", .{ name, option.description });
|
||||
if (option.enum_options) |enum_options| {
|
||||
const padding = " " ** 33;
|
||||
try out_stream.writeAll(padding ++ "Supported Values:\n");
|
||||
for (enum_options) |enum_option| {
|
||||
try out_stream.print(padding ++ " {s}\n", .{enum_option});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user