UNPKG

@kareemaly/researcher

Version:
66 lines (65 loc) 2.89 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.showCommand = showCommand; const fileSystemStorage_1 = require("../services/fileSystemStorage"); const logger_1 = require("../utils/logger"); const path_1 = __importDefault(require("path")); const log = (0, logger_1.createLogger)("cli:show"); function showCommand(program) { program .command("show") .description("Show search details") .argument("<id>", "search ID to show") .option("--content", "show processed content") .action(async (id, options, command) => { try { const globalOpts = command.parent?.opts(); const outputDir = path_1.default.resolve(globalOpts?.output || "research"); log("Showing search %s from: %s", id, outputDir); const storage = new fileSystemStorage_1.FileSystemStorage({ basePath: outputDir }); await storage.initialize(); const search = await storage.getSearch(id); if (!search) { console.error(`Search not found: ${id}`); process.exit(1); } // Print search details const date = new Date(search.timestamp).toLocaleString(); console.log(`\nSearch details for: ${search.id}`); console.log(`Performed: ${date}`); console.log(`Query: "${search.query}"`); console.log(`Type: ${search.type}`); if (search.location) { console.log(`Location: ${search.location}`); } console.log(`\nResults (${search.results.length}):`); // Print each result for (const [index, result] of search.results.entries()) { console.log(`\n${index + 1}. ${result.title}`); console.log(` URL: ${result.url}`); if (result.snippet) { console.log(` Summary: ${result.snippet}`); } // Show processed content if requested if (options.content) { const content = await storage.getContent(id, result.url); if (content) { console.log("\n Processed content:"); console.log(" " + content.text.slice(0, 500) + "..."); } else { console.log("\n No processed content available"); } } } } catch (error) { log.error("Failed to show search: %O", error); console.error("Failed to show search:", error instanceof Error ? error.message : error); process.exit(1); } }); }