authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-06-18 22:06:08 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-06-18 22:06:08 -07:00
logb72dd23d34b63a3648f7081295b233f9d969c4d2
tree22cdbdcb5a92fb412f5b7491da2d5c125e7950ea
parentd5f3d9ad04713fe889980e05a2a725d5ad4c8b57

cmd/license: allow it to be called from code and fix a missing line before Unspecified section


1 files changed, 10 insertions(+), 4 deletions(-)

src/cmd/license.zig+10-4
......@@ -1,5 +1,6 @@
11const std = @import("std");
22const gpa = std.heap.c_allocator;
3const string = []const u8;
34const style = @import("ansi").style;
45const licenses = @import("licenses");
56const extras = @import("extras");
......@@ -24,7 +25,12 @@ pub fn execute(args: [][]u8) !void {
2425 .update = false,
2526 .alloc = gpa,
2627 };
27 const top_module = try common.collect_deps_deep(cachepath, dir, &options);
28
29 try do(cachepath, dir, &options, std.io.getStdOut());
30}
31
32pub fn do(cachepath: string, dir: std.fs.Dir, options: *common.CollectOptions, outfile: std.fs.File) !void {
33 const top_module = try common.collect_deps_deep(cachepath, dir, options);
2834
2935 var master_list = List.init(gpa);
3036 errdefer master_list.deinit();
......@@ -63,9 +69,8 @@ pub fn execute(args: [][]u8) !void {
6369 try tracking_list.append(item);
6470 }
6571
66 const stdout = std.io.getStdOut();
67 const istty = stdout.isTty();
68 const writer = stdout.writer();
72 const istty = outfile.isTty();
73 const writer = outfile.writer();
6974 const Bold = if (!istty) "" else style.Bold;
7075 const Faint = if (!istty) "" else style.Faint;
7176 const ResetIntensity = if (!istty) "" else style.ResetIntensity;
......@@ -91,6 +96,7 @@ pub fn execute(args: [][]u8) !void {
9196 }
9297 }
9398 if (unspecified_list.items.len > 0) {
99 if (!first) try writer.writeAll("\n");
94100 try writer.writeAll(Bold);
95101 try writer.writeAll("Unspecified:\n");
96102 try writer.writeAll(ResetIntensity);