| ... | @@ -34,6 +34,14 @@ pub const ModFile = struct { | ... | @@ -34,6 +34,14 @@ pub const ModFile = struct { |
| 34 | return from_mapping(alloc, doc.mapping); | 34 | return from_mapping(alloc, doc.mapping); |
| 35 | } | 35 | } |
| 36 | | 36 | |
| | 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 | |
| 37 | pub fn from_mapping(alloc: *std.mem.Allocator, mapping: yaml.Mapping) !Self { | 45 | pub fn from_mapping(alloc: *std.mem.Allocator, mapping: yaml.Mapping) !Self { |
| 38 | const id = mapping.get_string("id"); | 46 | const id = mapping.get_string("id"); |
| 39 | const name = mapping.get("name").?.string; | 47 | const name = mapping.get("name").?.string; |