| ... | @@ -119,6 +119,8 @@ pub fn addOption(self: *OptionsStep, comptime T: type, name: []const u8, value: | ... | @@ -119,6 +119,8 @@ pub fn addOption(self: *OptionsStep, comptime T: type, name: []const u8, value: |
| 119 | out.print(" {},\n", .{std.zig.fmtId(field.name)}) catch unreachable; | 119 | out.print(" {},\n", .{std.zig.fmtId(field.name)}) catch unreachable; |
| 120 | } | 120 | } |
| 121 | out.writeAll("};\n") catch unreachable; | 121 | out.writeAll("};\n") catch unreachable; |
| | 122 | out.print("pub const {}: {s} = {s}.{s};\n", .{ std.zig.fmtId(name), @typeName(T), @typeName(T), std.zig.fmtId(@tagName(value)) }) catch unreachable; |
| | 123 | return; |
| 122 | }, | 124 | }, |
| 123 | else => {}, | 125 | else => {}, |
| 124 | } | 126 | } |
| ... | @@ -236,10 +238,15 @@ test "OptionsStep" { | ... | @@ -236,10 +238,15 @@ test "OptionsStep" { |
| 236 | | 238 | |
| 237 | const options = builder.addOptions(); | 239 | const options = builder.addOptions(); |
| 238 | | 240 | |
| | 241 | const KeywordEnum = enum { |
| | 242 | @"0.8.1", |
| | 243 | }; |
| | 244 | |
| 239 | options.addOption(usize, "option1", 1); | 245 | options.addOption(usize, "option1", 1); |
| 240 | options.addOption(?usize, "option2", null); | 246 | options.addOption(?usize, "option2", null); |
| 241 | options.addOption([]const u8, "string", "zigisthebest"); | 247 | options.addOption([]const u8, "string", "zigisthebest"); |
| 242 | options.addOption(?[]const u8, "optional_string", null); | 248 | options.addOption(?[]const u8, "optional_string", null); |
| | 249 | options.addOption(KeywordEnum, "keyword_enum", .@"0.8.1"); |
| 243 | options.addOption(std.builtin.Version, "version", try std.builtin.Version.parse("0.1.2")); | 250 | options.addOption(std.builtin.Version, "version", try std.builtin.Version.parse("0.1.2")); |
| 244 | options.addOption(std.SemanticVersion, "semantic_version", try std.SemanticVersion.parse("0.1.2-foo+bar")); | 251 | options.addOption(std.SemanticVersion, "semantic_version", try std.SemanticVersion.parse("0.1.2-foo+bar")); |
| 245 | | 252 | |
| ... | @@ -248,6 +255,10 @@ test "OptionsStep" { | ... | @@ -248,6 +255,10 @@ test "OptionsStep" { |
| 248 | \\pub const option2: ?usize = null; | 255 | \\pub const option2: ?usize = null; |
| 249 | \\pub const string: []const u8 = "zigisthebest"; | 256 | \\pub const string: []const u8 = "zigisthebest"; |
| 250 | \\pub const optional_string: ?[]const u8 = null; | 257 | \\pub const optional_string: ?[]const u8 = null; |
| | 258 | \\pub const KeywordEnum = enum { |
| | 259 | \\ @"0.8.1", |
| | 260 | \\}; |
| | 261 | \\pub const keyword_enum: KeywordEnum = KeywordEnum.@"0.8.1"; |
| 251 | \\pub const version: @import("std").builtin.Version = .{ | 262 | \\pub const version: @import("std").builtin.Version = .{ |
| 252 | \\ .major = 0, | 263 | \\ .major = 0, |
| 253 | \\ .minor = 1, | 264 | \\ .minor = 1, |