# HG changeset patch # User Robin Stumm # Date 1610834198 -3600 # Sat Jan 16 22:56:38 2021 +0100 # Node ID 6da99d1a0fb001026ad8acdb8a6c10b42edeb3dd # Parent c27b8d8e677ffbaf203e41ec37d5eebe87dc33f9 add filter option diff --git a/lib.zig b/lib.zig --- a/lib.zig +++ b/lib.zig @@ -5,8 +5,13 @@ pub const Options = struct { target: []const u8 = "src/embed.zig", dir: []const u8, + filter: ?fn ([]const u8) anyerror!bool = default_filter, }; +fn default_filter(_: []const u8) !bool { + return true; +} + pub fn writeZig(caller_allocator: *mem.Allocator, options: Options) !void { var zig_source = try fs.cwd().createFile(options.target, .{}); defer zig_source.close(); @@ -30,8 +35,14 @@ const entry = i.?; if (entry.kind != .File) continue; + const path = try mem.dupe(allocator, u8, entry.path[options.dir.len + "/".len ..]); + + if (options.filter) |filter| { + if (!try filter(path)) continue; + } + try entries.append(.{ - .path = try mem.dupe(allocator, u8, entry.path[options.dir.len + "/".len ..]), + .path = path, .target_path = try fs.path.relative(allocator, target_dir, entry.path), }); }