diff --git a/src/util/modfile.zig b/src/util/modfile.zig index 2625607542968c6778c08c768c711fce9215bc0a..c8a9f01958195d7af818859ff267c5ae6b706658 100644 --- a/src/util/modfile.zig +++ b/src/util/modfile.zig @@ -34,6 +34,14 @@ pub const ModFile = struct { return from_mapping(alloc, doc.mapping); } + pub fn from_dir(alloc: *std.mem.Allocator, dir: std.fs.Dir) !Self { + const file = try dir.openFile("zig.mod", .{}); + defer file.close(); + const input = try file.reader().readAllAlloc(alloc, mb); + const doc = try yaml.parse(alloc, input); + return from_mapping(alloc, doc.mapping); + } + pub fn from_mapping(alloc: *std.mem.Allocator, mapping: yaml.Mapping) !Self { const id = mapping.get_string("id"); const name = mapping.get("name").?.string;