UNPKG

abuse-plus

Version:
38 lines (30 loc) โ€ข 935 B
import { Command } from "commander"; import { LogManager } from "../core/logManager.js"; export const logsCommand = new Command("logs") .description("๐Ÿชต View or clear abuse CLI logs.") .argument("[count]", "Number of recent logs to show", null) .option("--clear", "Clear all logs") .action((count, options) => { if (options.clear) { LogManager.clear(); console.log("๐Ÿงน Logs cleared!"); return; } const logs = LogManager.readLogs(); if (!logs.length) { console.log("๐Ÿ“ญ No logs found."); return; } let selectedLogs = logs; if (count !== null) { const n = parseInt(count, 10); if (!isNaN(n) && n > 0) { selectedLogs = logs.slice(-n); } } console.log(`๐Ÿ“œ Showing ${selectedLogs.length} log(s):\n`); for (const log of selectedLogs) { console.log(LogManager.format(log)); console.log(); // spacing } });