| author | |
| committer | |
| log | bcdb68005ebf31399be9acf6b6897180d4efcaaf |
| tree | ba7a8e54a858b87655ddd51f2806fc4f8f42e6a4 |
| parent | 2a1a595dec91552d05b2f0c6c666f14dbb301e70 |
2 files changed, 27 insertions(+), 21 deletions(-)
src/cmd/aq.zig+26| ... | @@ -1,6 +1,9 @@ | ... | @@ -1,6 +1,9 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const gpa = std.heap.c_allocator; | 2 | const gpa = std.heap.c_allocator; |
| 3 | 3 | ||
| 4 | const zfetch = @import("zfetch"); | ||
| 5 | const json = @import("json"); | ||
| 6 | |||
| 4 | const u = @import("./../util/index.zig"); | 7 | const u = @import("./../util/index.zig"); |
| 5 | 8 | ||
| 6 | // | 9 | // |
| ... | @@ -21,6 +24,8 @@ pub fn execute(args: [][]u8) !void { | ... | @@ -21,6 +24,8 @@ pub fn execute(args: [][]u8) !void { |
| 21 | \\ | 24 | \\ |
| 22 | \\The subcommands available are: | 25 | \\The subcommands available are: |
| 23 | \\ - add Append this package to your dependencies | 26 | \\ - add Append this package to your dependencies |
| 27 | \\ - update Check your zig.mod dependencies for new versions | ||
| 28 | \\ - modile Print the zig.mod text for a new version | ||
| 24 | }); | 29 | }); |
| 25 | return; | 30 | return; |
| 26 | } | 31 | } |
| ... | @@ -34,3 +39,24 @@ pub fn execute(args: [][]u8) !void { | ... | @@ -34,3 +39,24 @@ pub fn execute(args: [][]u8) !void { |
| 34 | } | 39 | } |
| 35 | std.debug.panic("error: unknown command \"{s}\" for \"zigmod aq\"", .{args[0]}); | 40 | std.debug.panic("error: unknown command \"{s}\" for \"zigmod aq\"", .{args[0]}); |
| 36 | } | 41 | } |
| 42 | |||
| 43 | pub fn server_fetch(url: []const u8) !json.Value { | ||
| 44 | const req = try zfetch.Request.init(gpa, url, null); | ||
| 45 | defer req.deinit(); | ||
| 46 | |||
| 47 | var headers = zfetch.Headers.init(gpa); | ||
| 48 | defer headers.deinit(); | ||
| 49 | try headers.set("accept", "application/json"); | ||
| 50 | |||
| 51 | try req.do(.GET, headers, null); | ||
| 52 | |||
| 53 | const r = req.reader(); | ||
| 54 | const body_content = try r.readAllAlloc(gpa, std.math.maxInt(usize)); | ||
| 55 | const val = try json.parse(gpa, body_content); | ||
| 56 | |||
| 57 | if (val.get("message")) |msg| { | ||
| 58 | std.log.err("server: {s}", .{msg.String}); | ||
| 59 | return error.AquilaBadResponse; | ||
| 60 | } | ||
| 61 | return val; | ||
| 62 | } |
src/cmd/aquila/add.zig+1-21| ... | @@ -1,9 +1,6 @@ | ... | @@ -1,9 +1,6 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const gpa = std.heap.c_allocator; | 2 | const gpa = std.heap.c_allocator; |
| 3 | 3 | ||
| 4 | const zfetch = @import("zfetch"); | ||
| 5 | const json = @import("json"); | ||
| 6 | |||
| 7 | const u = @import("./../../util/index.zig"); | 4 | const u = @import("./../../util/index.zig"); |
| 8 | const aq = @import("./../aq.zig"); | 5 | const aq = @import("./../aq.zig"); |
| 9 | 6 | ||
| ... | @@ -14,24 +11,7 @@ pub fn execute(args: [][]u8) !void { | ... | @@ -14,24 +11,7 @@ pub fn execute(args: [][]u8) !void { |
| 14 | const pkg_id = args[0]; | 11 | const pkg_id = args[0]; |
| 15 | 12 | ||
| 16 | const url = try std.mem.join(gpa, "/", &.{ aq.server_root, pkg_id }); | 13 | const url = try std.mem.join(gpa, "/", &.{ aq.server_root, pkg_id }); |
| 17 | 14 | const val = try aq.server_fetch(url); | |
| 18 | const req = try zfetch.Request.init(gpa, url, null); | ||
| 19 | defer req.deinit(); | ||
| 20 | |||
| 21 | var headers = zfetch.Headers.init(gpa); | ||
| 22 | defer headers.deinit(); | ||
| 23 | try headers.set("accept", "application/json"); | ||
| 24 | |||
| 25 | try req.do(.GET, headers, null); | ||
| 26 | |||
| 27 | const r = req.reader(); | ||
| 28 | const body_content = try r.readAllAlloc(gpa, std.math.maxInt(usize)); | ||
| 29 | const val = try json.parse(gpa, body_content); | ||
| 30 | |||
| 31 | if (val.get("message")) |msg| { | ||
| 32 | std.log.err("server: {s}", .{msg.String}); | ||
| 33 | return; | ||
| 34 | } | ||
| 35 | 15 | ||
| 36 | const name = val.get(.{ "pkg", "name" }).?.String; | 16 | const name = val.get(.{ "pkg", "name" }).?.String; |
| 37 | 17 |