fix: handle relative paths in CLI

This commit is contained in:
Remi Gelinas
2024-07-17 16:51:16 -04:00
parent 3350e3c848
commit 368868f712
2 changed files with 5 additions and 4 deletions

View File

@@ -38,7 +38,10 @@ pub fn run(alloc: std.mem.Allocator) !u8 {
// If a config path is passed, validate it, otherwise validate default configs // If a config path is passed, validate it, otherwise validate default configs
if (opts.@"config-file") |config_path| { if (opts.@"config-file") |config_path| {
try cfg.loadFile(alloc, config_path); var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
const abs_path = try std.fs.cwd().realpath(config_path, &buf);
try cfg.loadFile(alloc, abs_path);
if (!cfg._errors.empty()) { if (!cfg._errors.empty()) {
try stdout.print("Config is not valid path={s}", .{config_path}); try stdout.print("Config is not valid path={s}", .{config_path});

View File

@@ -1687,9 +1687,7 @@ pub fn loadIter(
} }
pub fn loadFile(self: *Config, alloc: Allocator, path: []const u8) !void { pub fn loadFile(self: *Config, alloc: Allocator, path: []const u8) !void {
const cwd = std.fs.cwd(); var file = try std.fs.cwd().openFile(path, .{});
var file = try cwd.openFile(path, .{});
defer file.close(); defer file.close();
std.log.info("reading configuration file path={s}", .{path}); std.log.info("reading configuration file path={s}", .{path});