From d6b9e2e2c4b96f8191817f54deda3c5fbb7c45c5 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Thu, 28 Oct 2021 01:24:06 -0700 Subject: [PATCH] use new json api to clean up optional usage --- deps.zig | 13 +++++++++---- src/cmd/aq.zig | 4 ++-- src/cmd/aquila/add.zig | 4 ++-- src/cmd/zpm/search.zig | 6 +++--- src/cmd/zpm/tags.zig | 6 +++--- zigmod.lock | 3 ++- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/deps.zig b/deps.zig index d2aef9b712462c2bc2a59a8ecb6a008756d2aea5..20fab8f1b678c10ca96fe203a13fe4b97a473e41 100644 --- a/deps.zig +++ b/deps.zig @@ -52,6 +52,7 @@ const dirs = struct { pub const _yyhw90zkzgmu = cache ++ "/git/github.com/MasterQ32/zig-network"; pub const _u9w9dpp6p804 = cache ++ "/git/github.com/MasterQ32/zig-uri"; pub const _ocmr9rtohgcc = cache ++ "/git/github.com/nektro/zig-json"; + pub const _f7dubzb7cyqe = cache ++ "/git/github.com/nektro/zig-extras"; pub const _tnj3qf44tpeq = cache ++ "/git/github.com/nektro/zig-range"; pub const _2ovav391ivak = cache ++ "/git/github.com/nektro/zig-detect-license"; pub const _pt88y5d80m25 = cache ++ "/git/github.com/nektro/zig-licenses-text"; @@ -101,14 +102,18 @@ pub const package_data = struct { .directory = dirs._ejw82j2ipa0e, .pkg = Pkg{ .name = "zfetch", .path = .{ .path = dirs._ejw82j2ipa0e ++ "/src/main.zig" }, .dependencies = &.{ _9k24gimke1an.pkg.?, _csbnipaad8n7.pkg.?, _yyhw90zkzgmu.pkg.?, _u9w9dpp6p804.pkg.? } }, }; - pub const _ocmr9rtohgcc = Package{ - .directory = dirs._ocmr9rtohgcc, - .pkg = Pkg{ .name = "json", .path = .{ .path = dirs._ocmr9rtohgcc ++ "/src/lib.zig" }, .dependencies = null }, - }; pub const _tnj3qf44tpeq = Package{ .directory = dirs._tnj3qf44tpeq, .pkg = Pkg{ .name = "range", .path = .{ .path = dirs._tnj3qf44tpeq ++ "/src/lib.zig" }, .dependencies = null }, }; + pub const _f7dubzb7cyqe = Package{ + .directory = dirs._f7dubzb7cyqe, + .pkg = Pkg{ .name = "extras", .path = .{ .path = dirs._f7dubzb7cyqe ++ "/src/lib.zig" }, .dependencies = &.{ _tnj3qf44tpeq.pkg.? } }, + }; + pub const _ocmr9rtohgcc = Package{ + .directory = dirs._ocmr9rtohgcc, + .pkg = Pkg{ .name = "json", .path = .{ .path = dirs._ocmr9rtohgcc ++ "/src/lib.zig" }, .dependencies = &.{ _f7dubzb7cyqe.pkg.? } }, + }; pub const _pt88y5d80m25 = Package{ .directory = dirs._pt88y5d80m25, .pkg = Pkg{ .name = "licenses-text", .path = .{ .path = dirs._pt88y5d80m25 ++ "/src/lib.zig" }, .dependencies = null }, diff --git a/src/cmd/aq.zig b/src/cmd/aq.zig index c4fb9ae51b69e01b2269fe89c277024d0514c3da..250845c1cee00b46dc17e8f3bf57bb884e7a3896 100644 --- a/src/cmd/aq.zig +++ b/src/cmd/aq.zig @@ -57,8 +57,8 @@ pub fn server_fetch(url: string) !json.Value { const body_content = try r.readAllAlloc(gpa, std.math.maxInt(usize)); const val = try json.parse(gpa, body_content); - if (val.get("message")) |msg| { - std.log.err("server: {s}", .{msg.String}); + if (val.getT("message", .String)) |msg| { + std.log.err("server: {s}", .{msg}); return error.AquilaBadResponse; } return val; diff --git a/src/cmd/aquila/add.zig b/src/cmd/aquila/add.zig index 147f69ea71318466f2086e618b10d2d6a3e11aae..abc95ce5dbed1f447b365d89bb155c9062a3e26a 100644 --- a/src/cmd/aquila/add.zig +++ b/src/cmd/aquila/add.zig @@ -19,8 +19,8 @@ pub fn do(dir: std.fs.Dir, pkg_id: string) !string { const val = try aq.server_fetch(url); const pkg_url = try std.fmt.allocPrint(gpa, "https://{s}/{s}", .{ - val.get(.{ "repo", "domain" }).?.String, - val.get(.{ "pkg", "RemoteName" }).?.String, + val.getT(.{ "repo", "domain" }, .String).?, + val.getT(.{ "pkg", "RemoteName" }, .String).?, }); const m = try u.ModFile.from_dir(gpa, dir); diff --git a/src/cmd/zpm/search.zig b/src/cmd/zpm/search.zig index 8c0d270bf8bb92e291315a50ea0b290a710f071e..0fa942eee147d8e01a0d1b0725a8796d83dadae7 100644 --- a/src/cmd/zpm/search.zig +++ b/src/cmd/zpm/search.zig @@ -27,9 +27,9 @@ pub fn execute(args: [][]u8) !void { continue; } try arr.append(zpm.Package{ - .name = item.get("name").?.String, - .author = item.get("author").?.String, - .description = item.get("description").?.String, + .name = item.getT("name", .String).?, + .author = item.getT("author", .String).?, + .description = item.getT("description", .String).?, .tags = &.{}, .git = "", .root_file = "", diff --git a/src/cmd/zpm/tags.zig b/src/cmd/zpm/tags.zig index 52ed18734836a63b7b10a438d9e4bf8fe0d2e51f..6cc586a56f6acf83bccfd8f70b58c7b706d8e06e 100644 --- a/src/cmd/zpm/tags.zig +++ b/src/cmd/zpm/tags.zig @@ -22,7 +22,7 @@ pub fn execute(args: [][]u8) !void { const name_col_width = blk: { var w: usize = 4; for (val.Array) |tag| { - const len = tag.get("name").?.String.len; + const len = tag.getT("name", .String).?.len; if (len > w) { w = len; } @@ -35,10 +35,10 @@ pub fn execute(args: [][]u8) !void { try out.writeAll("DESCRIPTION\n"); for (val.Array) |tag| { - const name = tag.get("name").?.String; + const name = tag.getT("name", .String).?; try out.writeAll(name); try print_c_n(out, ' ', name_col_width - name.len); - try out.writeAll(tag.get("description").?.String); + try out.writeAll(tag.getT("description", .String).?); try out.writeAll("\n"); } } diff --git a/zigmod.lock b/zigmod.lock index 330bab9351fcf6a6188e80b64fd7bfb7e57170e8..0caaf39c12042a5ea5cd283ce4d8fba6ffe7cff6 100644 --- a/zigmod.lock +++ b/zigmod.lock @@ -8,7 +8,8 @@ git https://github.com/truemedian/zfetch commit-77fdd34e90db02f1224cdc7e5231ecd0 git https://github.com/truemedian/hzzp commit-91ab8e741992e8db30b3ee1cd9e7cd5a072ca294 git https://github.com/MasterQ32/zig-network commit-0439bd7127ecb8f927a5cecb0beeb1569db2fb95 git https://github.com/MasterQ32/zig-uri commit-52cdd2061bec0579519f0d30280597f3a1db8b75 -git https://github.com/nektro/zig-json commit-3ea23e8ae3798d3929b4c4b54ce739a67914f3ec +git https://github.com/nektro/zig-json commit-7f0e661371d41cfdc8b1649ed00e7a750c82e57a +git https://github.com/nektro/zig-extras commit-090ee5f1834af4ed7714101b24d7daec84572390 git https://github.com/nektro/zig-range commit-890ca308fe09b3d5c866d5cfb3b3d7a95dbf939f git https://github.com/nektro/zig-detect-license commit-d4544410f811c402b866f21f63588d1aae1b2d90 git https://github.com/nektro/zig-licenses-text commit-3c07c6e4eb0965dafd0b029c632f823631b3169c -- 2.54.0