chore: move TOML loading + parsing to it's own file
Unfortunately, this leaks memory. I should try using loadContents or perhaps I should try contributing some fixes upstream.
This commit is contained in:
parent
51115cba86
commit
584a1637ce
26
src/main.zig
26
src/main.zig
|
@ -43,11 +43,10 @@ pub fn main() anyerror!void {
|
||||||
const save_path = try savePath(allocator, data_path);
|
const save_path = try savePath(allocator, data_path);
|
||||||
defer allocator.free(save_path);
|
defer allocator.free(save_path);
|
||||||
|
|
||||||
// Read Config File
|
const config = try loadConfig(allocator, config_path);
|
||||||
log.info("Config File: {s}", .{config_path});
|
_ = config;
|
||||||
const table = try toml.parseFile(allocator, config_path, null);
|
|
||||||
defer table.deinit();
|
log.debug("got past loadConfig()", .{});
|
||||||
log.info("{?}", .{table});
|
|
||||||
|
|
||||||
// Handle CLI Input
|
// Handle CLI Input
|
||||||
const result = try clap.parse(clap.Help, ¶ms, clap.parsers.default, .{});
|
const result = try clap.parse(clap.Help, ¶ms, clap.parsers.default, .{});
|
||||||
|
@ -93,6 +92,23 @@ pub fn handleArguments(allocator: Allocator, data_path: []const u8, result: *con
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Config = struct {
|
||||||
|
// TODO: Add Config Fields
|
||||||
|
// TODO: Move to it's own file? config.zig?
|
||||||
|
};
|
||||||
|
|
||||||
|
// FIXME: TOML Library Leaks memory here
|
||||||
|
// Either I should improve the TOML library, or try some of the even less used ones :thinking
|
||||||
|
fn loadConfig(allocator: Allocator, config_path: []const u8) !Config {
|
||||||
|
// _ = allocator;
|
||||||
|
// _ = config_path;
|
||||||
|
|
||||||
|
const table = try toml.parseFile(allocator, config_path, null);
|
||||||
|
table.deinit();
|
||||||
|
|
||||||
|
return .{};
|
||||||
|
}
|
||||||
|
|
||||||
fn configFilePath(allocator: Allocator, data_path: []const u8) ![]const u8 {
|
fn configFilePath(allocator: Allocator, data_path: []const u8) ![]const u8 {
|
||||||
const path = try std.fs.path.join(allocator, &[_][]const u8{ data_path, "zba", "config.toml" });
|
const path = try std.fs.path.join(allocator, &[_][]const u8{ data_path, "zba", "config.toml" });
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue