Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,21 @@ pub fn main(init: std.process.Init) !void {

defer allocator.free(config_path);

const config_file = try std.Io.Dir.cwd().readFileAllocOptions(init.io, config_path, allocator, .unlimited, .@"1", 0);
defer allocator.free(config_file);

const parsed_config = zon.parse.fromSliceAlloc(Config, allocator, config_file, null, .{ .free_on_error = true }) catch |e| {
switch (e) {
error.ParseZon => {
std.debug.print("[{s}] Could not parse config file!\n", .{err_color.format("Error")});
return;
},
error.OutOfMemory => return e,
}
const parsed_config = lbl: {
const config_file = std.Io.Dir.cwd().readFileAllocOptions(init.io, config_path, allocator, .unlimited, .@"1", 0) catch {
break :lbl Config{};
};
defer allocator.free(config_file);

break :lbl zon.parse.fromSliceAlloc(Config, allocator, config_file, null, .{ .free_on_error = true }) catch |e| {
switch (e) {
error.ParseZon => {
std.debug.print("[{s}] Could not parse config file!\n", .{err_color.format("Error")});
return;
},
error.OutOfMemory => return e,
}
};
};

program.model.config = parsed_config;
Expand Down