| ... | ... | @@ -129,11 +129,11 @@ pub fn addOption(self: *OptionsStep, comptime T: type, name: []const u8, value: |
| 129 | 129 | out.writeAll(";\n") catch unreachable; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | // TODO: non-recursive? |
| 132 | 133 | fn printLiteral(out: anytype, val: anytype, indent: u8) !void { |
| 133 | 134 | const T = @TypeOf(val); |
| 134 | 135 | switch (@typeInfo(T)) { |
| 135 | 136 | .Array => { |
| 136 | | // TODO: non-recursive? |
| 137 | 137 | try out.print("{s} {{\n", .{@typeName(T)}); |
| 138 | 138 | for (val) |item| { |
| 139 | 139 | try out.writeByteNTimes(' ', indent + 4); |
| ... | ... | @@ -156,7 +156,20 @@ fn printLiteral(out: anytype, val: anytype, indent: u8) !void { |
| 156 | 156 | try out.writeByteNTimes(' ', indent); |
| 157 | 157 | try out.writeAll("}"); |
| 158 | 158 | }, |
| 159 | | else => try out.print("{any}", .{val}), |
| 159 | .Optional => { |
| 160 | if (val) |inner| { |
| 161 | return printLiteral(out, inner, indent); |
| 162 | } else { |
| 163 | return out.writeAll("null"); |
| 164 | } |
| 165 | }, |
| 166 | .Void, |
| 167 | .Bool, |
| 168 | .Int, |
| 169 | .Float, |
| 170 | .Null, |
| 171 | => try out.print("{any}", .{val}), |
| 172 | else => @compileError(comptime std.fmt.comptimePrint("`{s}` are not yet supported as build options", .{@tagName(@typeInfo(T))})), |
| 160 | 173 | } |
| 161 | 174 | } |
| 162 | 175 | |
| ... | ... | @@ -283,6 +296,7 @@ test "OptionsStep" { |
| 283 | 296 | |
| 284 | 297 | options.addOption(usize, "option1", 1); |
| 285 | 298 | options.addOption(?usize, "option2", null); |
| 299 | options.addOption(?usize, "option3", 3); |
| 286 | 300 | options.addOption([]const u8, "string", "zigisthebest"); |
| 287 | 301 | options.addOption(?[]const u8, "optional_string", null); |
| 288 | 302 | options.addOption([2][2]u16, "nested_array", nested_array); |
| ... | ... | @@ -294,6 +308,7 @@ test "OptionsStep" { |
| 294 | 308 | try std.testing.expectEqualStrings( |
| 295 | 309 | \\pub const option1: usize = 1; |
| 296 | 310 | \\pub const option2: ?usize = null; |
| 311 | \\pub const option3: ?usize = 3; |
| 297 | 312 | \\pub const string: []const u8 = "zigisthebest"; |
| 298 | 313 | \\pub const optional_string: ?[]const u8 = null; |
| 299 | 314 | \\pub const nested_array: [2][2]u16 = [2][2]u16 { |