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 {...@@ -56,14 +56,24 @@ pub fn execute(args: [][]u8) !void {
56 }56 }
57 }57 }
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
59 const file = try std.fs.cwd().openFile("zig.mod", .{ .read = true, .write = true });67 const file = try std.fs.cwd().openFile("zig.mod", .{ .read = true, .write = true });
60 try file.seekTo(try file.getEndPos());68 try file.seekTo(try file.getEndPos());
6169
62 const file_w = file.writer();70 const file_w = file.writer();
63 try file_w.print("\n", .{});71 try file_w.print("\n", .{});
64 try file_w.print(" - src: git {s}\n", .{std.mem.trimRight(u8, found.git, ".git")});72 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});73 if (!has_zigdotmod) {
66 try file_w.print(" main: {s}\n", .{found.root_file.?[1..]});74 try file_w.print(" name: {s}\n", .{found.name});
75 try file_w.print(" main: {s}\n", .{found.root_file.?[1..]});
76 }
6777
68 std.log.info("Successfully added package {s} by {s}", .{ found.name, found.author });78 std.log.info("Successfully added package {s} by {s}", .{ found.name, found.author });
69}79}