authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-07-31 19:04:49 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-07-31 19:04:49 -07:00
logcde630a01ee18fd25ddd4972e6c2c2b4dc2d49fd
treed1f16086d5191450c3826d7bb490cb1f4b523661
parentfb9c97be027e0d0d5fc714bcedc15dfbcb362d24

util/modfile- add fs.Dir init


1 files changed, 8 insertions(+), 0 deletions(-)

src/util/modfile.zig+8
......@@ -34,6 +34,14 @@ pub const ModFile = struct {
3434 return from_mapping(alloc, doc.mapping);
3535 }
3636
37 pub fn from_dir(alloc: *std.mem.Allocator, dir: std.fs.Dir) !Self {
38 const file = try dir.openFile("zig.mod", .{});
39 defer file.close();
40 const input = try file.reader().readAllAlloc(alloc, mb);
41 const doc = try yaml.parse(alloc, input);
42 return from_mapping(alloc, doc.mapping);
43 }
44
3745 pub fn from_mapping(alloc: *std.mem.Allocator, mapping: yaml.Mapping) !Self {
3846 const id = mapping.get_string("id");
3947 const name = mapping.get("name").?.string;