| ... | @@ -1,55 +0,0 @@ |
| 1 | const std = @import("std"); |
| 2 | const gpa = std.heap.c_allocator; |
| 3 | |
| 4 | const u = @import("./util/index.zig"); |
| 5 | |
| 6 | // |
| 7 | // |
| 8 | |
| 9 | pub fn execute(args: [][]u8) !void { |
| 10 | // |
| 11 | u.assert(args.len >= 1, "missing package <type> parameter", .{}); |
| 12 | u.assert(args.len >= 2, "missing package <path> parameter", .{}); |
| 13 | |
| 14 | const dept = args[0]; |
| 15 | const path = args[1]; |
| 16 | |
| 17 | const dep_type = std.meta.stringToEnum(u.DepType, dept); |
| 18 | u.assert(dep_type != null, "provided <type> parameter \"{}\" is not a valid dependency type", .{dept}); |
| 19 | |
| 20 | const m = try u.ModFile.init(gpa, "zig.mod"); |
| 21 | for (m.deps) |d| { |
| 22 | u.assert(!(d.type == dep_type.? and std.mem.eql(u8, d.path, path)), "dependency already added, skipping!", .{}); |
| 23 | } |
| 24 | |
| 25 | const ndl = &std.ArrayList(u.Dep).init(gpa); |
| 26 | for (m.deps) |d| { |
| 27 | try ndl.append(d); |
| 28 | } |
| 29 | try ndl.append(u.Dep{ |
| 30 | .type = dep_type.?, |
| 31 | .path = path, |
| 32 | .name = "", |
| 33 | .main = "", |
| 34 | .version = "", |
| 35 | .c_include_dirs = &[_][]const u8{}, |
| 36 | .c_source_flags = &[_][]const u8{}, |
| 37 | .c_source_files = &[_][]const u8{}, |
| 38 | }); |
| 39 | |
| 40 | // |
| 41 | const f = try std.fs.cwd().createFile("zig.mod", .{}); |
| 42 | defer f.close(); |
| 43 | |
| 44 | const w = f.writer(); |
| 45 | try w.print("name: {}\n", .{m.name}); |
| 46 | try w.print("main: {}\n", .{m.main}); |
| 47 | try w.print("dependencies:\n", .{}); |
| 48 | |
| 49 | for (ndl.items) |d| { |
| 50 | try w.print("- type: {}\n", .{@tagName(d.type)}); |
| 51 | try w.print(" path: {}\n", .{d.path}); |
| 52 | } |
| 53 | |
| 54 | u.print("Successfully added {s}", .{path}); |
| 55 | } |