authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-05-06 02:31:08 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-05-06 02:31:08 -07:00
log5bf056c9102e5cfd461c7c1ece90283958a7d8cb
treeea16218aa1edcd47ae5fd57a7719873879a700b7
parent123d3e9f5d5d17b6a78bad59c83c64be1a592f20

cmd/zpm/add: use `std.json` for api parsing


1 files changed, 13 insertions(+), 13 deletions(-)

src/cmd/zpm_add.zig+13-13
......@@ -2,7 +2,6 @@ const std = @import("std");
22const gpa = std.heap.c_allocator;
33
44const zfetch = @import("zfetch");
5const json = @import("json");
65
76const u = @import("./../util/index.zig");
87
......@@ -30,11 +29,12 @@ pub fn execute(args: [][]u8) !void {
3029 const r = req.reader();
3130
3231 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, .{});
3434
3535 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])) {
3838 break :blk pkg;
3939 }
4040 }
......@@ -42,17 +42,17 @@ pub fn execute(args: [][]u8) !void {
4242 unreachable;
4343 };
4444
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", .{});
4646
4747 const self_module = try u.ModFile.init(gpa, "zig.mod");
4848 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});
5151 }
5252 }
5353 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});
5656 }
5757 }
5858
......@@ -61,9 +61,9 @@ pub fn execute(args: [][]u8) !void {
6161
6262 const file_w = file.writer();
6363 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..]});
6767
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 });
6969}