mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-11-05 23:29:27 +01:00
21 lines
866 B
Zig
21 lines
866 B
Zig
//! Shared code for script build scripts
|
|
const std = @import("std");
|
|
|
|
pub const confgen_json_opt = std.json.ParseOptions{ .ignore_unknown_fields = true };
|
|
|
|
/// Retrieve some confgen options given a relative path to the dotfile root and a struct type
|
|
/// with a field for each option.
|
|
pub fn confgenGet(comptime T: type, root_path: []const u8, alloc: std.mem.Allocator) !T {
|
|
const optsjson = try std.fs.path.join(alloc, &.{ root_path, "cgout", "opts.json" });
|
|
defer alloc.free(optsjson);
|
|
|
|
var file = try std.fs.cwd().openFile(optsjson, .{});
|
|
defer file.close();
|
|
var buf_reader = std.io.bufferedReader(file.reader());
|
|
|
|
var reader = std.json.Reader(1024 * 8, @TypeOf(buf_reader.reader()))
|
|
.init(alloc, buf_reader.reader());
|
|
defer reader.deinit();
|
|
|
|
return try std.json.parseFromTokenSource(T, alloc, &reader, confgen_json_opt);
|
|
}
|