| ... | ... | @@ -2,7 +2,6 @@ const std = @import("std"); |
| 2 | 2 | const gpa = std.heap.c_allocator; |
| 3 | 3 | |
| 4 | 4 | const zfetch = @import("zfetch"); |
| 5 | | const json = @import("json"); |
| 6 | 5 | |
| 7 | 6 | const u = @import("./../util/index.zig"); |
| 8 | 7 | |
| ... | ... | @@ -30,11 +29,12 @@ pub fn execute(args: [][]u8) !void { |
| 30 | 29 | const r = req.reader(); |
| 31 | 30 | |
| 32 | 31 | const body_content = try r.readAllAlloc(gpa, std.math.maxInt(usize)); |
| 33 | | const val = try json.parse(gpa, body_content); |
| 32 | var stream = std.json.TokenStream.init(body_content); |
| 33 | const val = try std.json.parse([]Zpm.Package, &stream, .{}); |
| 34 | 34 | |
| 35 | 35 | const found = blk: { |
| 36 | | for (val.Array) |pkg| { |
| 37 | | if (std.mem.eql(u8, pkg.get("name").?.String, args[0])) { |
| 36 | for (val) |pkg| { |
| 37 | if (std.mem.eql(u8, pkg.name, args[0])) { |
| 38 | 38 | break :blk pkg; |
| 39 | 39 | } |
| 40 | 40 | } |
| ... | ... | @@ -42,17 +42,17 @@ pub fn execute(args: [][]u8) !void { |
| 42 | 42 | unreachable; |
| 43 | 43 | }; |
| 44 | 44 | |
| 45 | | u.assert(found.get("root_file") != null, "package must have an entry point to be able to be added to your dependencies", .{}); |
| 45 | u.assert(found.root_file != null, "package must have an entry point to be able to be added to your dependencies", .{}); |
| 46 | 46 | |
| 47 | 47 | const self_module = try u.ModFile.init(gpa, "zig.mod"); |
| 48 | 48 | for (self_module.deps) |dep| { |
| 49 | | if (std.mem.eql(u8, dep.name, found.get("name").?.String)) { |
| 50 | | std.log.warn("dependency with name '{s}' already exists in your dependencies", .{found.get("name").?.String}); |
| 49 | if (std.mem.eql(u8, dep.name, found.name)) { |
| 50 | std.log.warn("dependency with name '{s}' already exists in your dependencies", .{found.name}); |
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | for (self_module.devdeps) |dep| { |
| 54 | | if (std.mem.eql(u8, dep.name, found.get("name").?.String)) { |
| 55 | | std.log.warn("dependency with name '{s}' already exists in your dev_dependencies", .{found.get("name").?.String}); |
| 54 | if (std.mem.eql(u8, dep.name, found.name)) { |
| 55 | std.log.warn("dependency with name '{s}' already exists in your dev_dependencies", .{found.name}); |
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | |
| ... | ... | @@ -61,9 +61,9 @@ pub fn execute(args: [][]u8) !void { |
| 61 | 61 | |
| 62 | 62 | const file_w = file.writer(); |
| 63 | 63 | try file_w.print("\n", .{}); |
| 64 | | try file_w.print(" - src: git {s}\n", .{found.get("git").?.String}); |
| 65 | | try file_w.print(" name: {s}\n", .{found.get("name").?.String}); |
| 66 | | try file_w.print(" main: {s}\n", .{found.get("root_file").?.String[1..]}); |
| 64 | try file_w.print(" - src: git {s}\n", .{found.git}); |
| 65 | try file_w.print(" name: {s}\n", .{found.name}); |
| 66 | try file_w.print(" main: {s}\n", .{found.root_file.?[1..]}); |
| 67 | 67 | |
| 68 | | std.log.info("Successfully added package {s} by {s}", .{ found.get("name").?.String, found.get("author").?.String }); |
| 68 | std.log.info("Successfully added package {s} by {s}", .{ found.name, found.author }); |
| 69 | 69 | } |