| ... | ... | @@ -1,6 +1,9 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const gpa = std.heap.c_allocator; |
| 3 | 3 | |
| 4 | const zfetch = @import("zfetch"); |
| 5 | const json = @import("json"); |
| 6 | |
| 4 | 7 | const u = @import("./../util/index.zig"); |
| 5 | 8 | |
| 6 | 9 | // |
| ... | ... | @@ -8,8 +11,11 @@ const u = @import("./../util/index.zig"); |
| 8 | 11 | |
| 9 | 12 | pub const commands = struct { |
| 10 | 13 | pub const add = @import("./zpm_add.zig"); |
| 14 | pub const showjson = @import("./zpm/showjson.zig"); |
| 11 | 15 | }; |
| 12 | 16 | |
| 17 | pub const server_root = "https://zpm.random-projects.net/api"; |
| 18 | |
| 13 | 19 | pub fn execute(args: [][]u8) !void { |
| 14 | 20 | if (args.len == 0) { |
| 15 | 21 | std.debug.warn("{s}\n", .{ |
| ... | ... | @@ -32,3 +38,13 @@ pub fn execute(args: [][]u8) !void { |
| 32 | 38 | } |
| 33 | 39 | std.debug.panic("error: unknown command \"{s}\" for \"zigmod zpm\"", .{args[0]}); |
| 34 | 40 | } |
| 41 | |
| 42 | pub fn server_fetch(url: []const u8) !json.Value { |
| 43 | const req = try zfetch.Request.init(gpa, url, null); |
| 44 | defer req.deinit(); |
| 45 | try req.do(.GET, null, null); |
| 46 | const r = req.reader(); |
| 47 | const body_content = try r.readAllAlloc(gpa, std.math.maxInt(usize)); |
| 48 | const val = try json.parse(gpa, body_content); |
| 49 | return val; |
| 50 | } |