--font-family CLI config

This commit is contained in:
Mitchell Hashimoto
2022-09-29 14:51:31 -07:00
parent 7eac0afff2
commit 53aab0a163
4 changed files with 162 additions and 112 deletions

View File

@@ -60,6 +60,8 @@ pub fn parse(comptime T: type, alloc: Allocator, dst: *T, iter: anytype) !void {
try parseIntoField(T, arena_alloc, dst, key, value);
}
}
if (@hasDecl(T, "finalize")) try dst.finalize();
}
/// Parse a single key/value pair into the destination type T.
@@ -193,6 +195,28 @@ test "parse: simple" {
try testing.expect(!data.@"b-f");
}
test "parse: finalize" {
const testing = std.testing;
var data: struct {
a: []const u8 = "",
_arena: ?ArenaAllocator = null,
pub fn finalize(self: *@This()) !void {
self.a = "YO";
}
} = .{};
defer if (data._arena) |arena| arena.deinit();
var iter = try std.process.ArgIteratorGeneral(.{}).init(
testing.allocator,
"--a=42",
);
defer iter.deinit();
try parse(@TypeOf(data), testing.allocator, &data, &iter);
try testing.expectEqualStrings("YO", data.a);
}
test "parseIntoField: string" {
const testing = std.testing;
var arena = ArenaAllocator.init(testing.allocator);