authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-05-06 02:45:03 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-05-06 02:45:03 -07:00
log579e961999dc77531c04deecbe099445de94ce4f
tree6cab52d154ac667a2c6e2ef27b7c4d0f40f97d42
parent0550a29db11770ee97e53b9edbceff5cacb739b0

cmd/zpm/add: only print `name` and `main` if upstream does not have a `zig.mod`


1 files changed, 12 insertions(+), 2 deletions(-)

src/cmd/zpm_add.zig+12-2
......@@ -56,14 +56,24 @@ pub fn execute(args: [][]u8) !void {
5656 }
5757 }
5858
59 const has_zigdotmod = blk: {
60 const _url = try std.mem.join(gpa, "/", &.{ found.git, "blob", "HEAD", "zig.mod" });
61 const _req = try zfetch.Request.init(gpa, _url, null);
62 defer _req.deinit();
63 try _req.do(.GET, null, null);
64 break :blk _req.status.code == 200;
65 };
66
5967 const file = try std.fs.cwd().openFile("zig.mod", .{ .read = true, .write = true });
6068 try file.seekTo(try file.getEndPos());
6169
6270 const file_w = file.writer();
6371 try file_w.print("\n", .{});
6472 try file_w.print(" - src: git {s}\n", .{std.mem.trimRight(u8, found.git, ".git")});
65 try file_w.print(" name: {s}\n", .{found.name});
66 try file_w.print(" main: {s}\n", .{found.root_file.?[1..]});
73 if (!has_zigdotmod) {
74 try file_w.print(" name: {s}\n", .{found.name});
75 try file_w.print(" main: {s}\n", .{found.root_file.?[1..]});
76 }
6777
6878 std.log.info("Successfully added package {s} by {s}", .{ found.name, found.author });
6979}