37 lines
1.4 KiB
Zig
37 lines
1.4 KiB
Zig
const std = @import("std");
|
|
const zfin = @import("../root.zig");
|
|
const cli = @import("common.zig");
|
|
|
|
pub fn run(allocator: std.mem.Allocator, config: zfin.Config, subcommand: []const u8, out: *std.Io.Writer) !void {
|
|
if (std.mem.eql(u8, subcommand, "stats")) {
|
|
try out.print("Cache directory: {s}\n", .{config.cache_dir});
|
|
std.fs.cwd().access(config.cache_dir, .{}) catch {
|
|
try out.print(" (empty -- no cached data)\n", .{});
|
|
return;
|
|
};
|
|
var dir = std.fs.cwd().openDir(config.cache_dir, .{ .iterate = true }) catch {
|
|
try out.print(" (empty -- no cached data)\n", .{});
|
|
return;
|
|
};
|
|
defer dir.close();
|
|
var count: usize = 0;
|
|
var iter = dir.iterate();
|
|
while (iter.next() catch null) |entry| {
|
|
if (entry.kind == .directory) {
|
|
try out.print(" {s}/\n", .{entry.name});
|
|
count += 1;
|
|
}
|
|
}
|
|
if (count == 0) {
|
|
try out.print(" (empty -- no cached data)\n", .{});
|
|
} else {
|
|
try out.print("\n {d} symbol(s) cached\n", .{count});
|
|
}
|
|
} else if (std.mem.eql(u8, subcommand, "clear")) {
|
|
var store = zfin.cache.Store.init(allocator, config.cache_dir);
|
|
try store.clearAll();
|
|
try out.writeAll("Cache cleared.\n");
|
|
} else {
|
|
try cli.stderrPrint("Unknown cache subcommand. Use 'stats' or 'clear'.\n");
|
|
}
|
|
}
|