From cde630a01ee18fd25ddd4972e6c2c2b4dc2d49fd Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sat, 31 Jul 2021 19:04:49 -0700 Subject: [PATCH] util/modfile- add fs.Dir init --- src/util/modfile.zig | 8 ++++++++ 1 file changed, 8 insertions(+) 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; -- 2.54.0