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 @@...@@ -1,5 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const gpa = std.heap.c_allocator;2const gpa = std.heap.c_allocator;
3const string = []const u8;
3const style = @import("ansi").style;4const style = @import("ansi").style;
4const licenses = @import("licenses");5const licenses = @import("licenses");
5const extras = @import("extras");6const extras = @import("extras");
...@@ -24,7 +25,12 @@ pub fn execute(args: [][]u8) !void {...@@ -24,7 +25,12 @@ pub fn execute(args: [][]u8) !void {
24 .update = false,25 .update = false,
25 .alloc = gpa,26 .alloc = gpa,
26 };27 };
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
29 var master_list = List.init(gpa);35 var master_list = List.init(gpa);
30 errdefer master_list.deinit();36 errdefer master_list.deinit();
...@@ -63,9 +69,8 @@ pub fn execute(args: [][]u8) !void {...@@ -63,9 +69,8 @@ pub fn execute(args: [][]u8) !void {
63 try tracking_list.append(item);69 try tracking_list.append(item);
64 }70 }
6571
66 const stdout = std.io.getStdOut();72 const istty = outfile.isTty();
67 const istty = stdout.isTty();73 const writer = outfile.writer();
68 const writer = stdout.writer();
69 const Bold = if (!istty) "" else style.Bold;74 const Bold = if (!istty) "" else style.Bold;
70 const Faint = if (!istty) "" else style.Faint;75 const Faint = if (!istty) "" else style.Faint;
71 const ResetIntensity = if (!istty) "" else style.ResetIntensity;76 const ResetIntensity = if (!istty) "" else style.ResetIntensity;
...@@ -91,6 +96,7 @@ pub fn execute(args: [][]u8) !void {...@@ -91,6 +96,7 @@ pub fn execute(args: [][]u8) !void {
91 }96 }
92 }97 }
93 if (unspecified_list.items.len > 0) {98 if (unspecified_list.items.len > 0) {
99 if (!first) try writer.writeAll("\n");
94 try writer.writeAll(Bold);100 try writer.writeAll(Bold);
95 try writer.writeAll("Unspecified:\n");101 try writer.writeAll("Unspecified:\n");
96 try writer.writeAll(ResetIntensity);102 try writer.writeAll(ResetIntensity);