mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-06-02 03:19:54 +02:00
improve confgenGet API
This commit is contained in:
parent
2b9c4a88e0
commit
c5a893bcdf
|
@ -3,9 +3,12 @@ const std = @import("std");
|
|||
|
||||
pub const confgen_json_opt = std.json.ParseOptions{ .ignore_unknown_fields = true };
|
||||
|
||||
/// Retrieve some confgen options given a path to the opts.json file and a struct type
|
||||
/// 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, optsjson: []const u8, alloc: std.mem.Allocator) !T {
|
||||
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());
|
||||
|
@ -15,5 +18,4 @@ pub fn confgenGet(comptime T: type, optsjson: []const u8, alloc: std.mem.Allocat
|
|||
defer reader.deinit();
|
||||
|
||||
return try std.json.parseFromTokenSource(T, alloc, &reader, confgen_json_opt);
|
||||
//return try std.json.parseFromSlice(T, alloc, out.stdout, confgen_json_opt);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ pub fn build(b: *std.build.Builder) !void {
|
|||
|
||||
const cg_opt = try common.confgenGet(struct {
|
||||
term_font: []const u8,
|
||||
}, "../cgout/opts.json", b.allocator);
|
||||
}, "..", b.allocator);
|
||||
|
||||
const opts = b.addOptions();
|
||||
opts.addOption([]const u8, "font", cg_opt.term_font);
|
||||
|
|
Loading…
Reference in a new issue