fix rules failing no-prefix extracts

This commit is contained in:
JOLIMAITRE Matthieu 2024-08-07 11:18:17 +02:00
parent 8c18398ae4
commit fa524a5976
4 changed files with 54 additions and 5 deletions

38
example.ts Executable file
View file

@ -0,0 +1,38 @@
#!/bin/env -S deno run
import { extr } from "./mod.ts"
const date = ["month", " ", "day", " ", "h", ":", "m", ":", "s"] as const;
const service = extr("", ...date, " ", "device", " ", "service", "[", "pid", "]: ", "line");
const kernel_ = extr("", ...date, " ", "device", " kernel: ", "line");
const lines = [
"août 06 09:25:18 navis systemd[1]: Finished Load Kernel Module configfs.",
"août 06 09:25:18 navis systemd[1]: modprobe@drm.service: Succeeded.",
"août 06 09:25:18 navis systemd[1]: Finished Load Kernel Module drm.",
"août 06 09:25:18 navis systemd[1]: Mounting Kernel Configuration File System...",
"août 06 09:25:18 navis kernel: fuse: init (API version 7.32)",
"août 06 09:25:18 navis systemd[1]: modprobe@fuse.service: Succeeded.",
"août 06 09:25:18 navis systemd[1]: Finished Load Kernel Module fuse.",
"août 06 09:25:18 navis systemd[1]: Mounted Kernel Configuration File System.",
"août 06 09:25:18 navis systemd[1]: Mounting FUSE Control File System...",
"août 06 09:25:18 navis systemd[1]: Mounted FUSE Control File System.",
"août 06 09:25:18 navis kernel: EXT4-fs (sda4): re-mounted. Opts: errors=remount-ro",
"août 06 09:25:18 navis systemd[1]: Finished Remount Root and Kernel File Systems.",
"août 06 09:25:18 navis systemd[1]: Condition check resulted in Rebuild Hardware Database being skipped.",
"août 06 09:25:18 navis systemd[1]: Condition check resulted in Platform Persistent Storage Archival being skipped.",
"août 06 09:25:18 navis systemd[1]: Starting Load/Save Random Seed...",
"août 06 09:25:18 navis systemd[1]: Starting Create System Users...",
"août 06 09:25:18 navis kernel: lp: driver loaded but no devices found",
"août 06 09:25:18 navis kernel: ppdev: user-space parallel port driver",
"août 06 09:25:18 navis systemd[1]: Finished Load/Save Random Seed.",
"août 06 09:25:18 navis systemd[1]: Finished Load Kernel Modules.",
"août 06 09:25:18 navis systemd[1]: Condition check resulted in First Boot Complete being skipped.",
"août 06 09:25:18 navis systemd[1]: Starting Apply Kernel Variables...",
"août 06 09:25:18 navis systemd[1]: Finished Create System Users.",
];
const mapped = lines.map(line => service.or(kernel_).get(line));
const failed = mapped.filter(m => m === null).length;
const content = mapped.filter(m => m !== null).map(m => "service" in m! ? [m.service, m.line] : ["kernel", m!.line]);
console.log({ failed, content })