UNPKG

codetainer

Version:

A clean and simple CLI to manage and store code snippets with ease.

28 lines (24 loc) 941 B
import chalk from "chalk"; import { loadSnippets } from "../utils/snippetStore.js"; export function registerSearchCommand(program) { program .command("search <query>") .description("Search snippets by name or code content") .action((query) => { const snippets = loadSnippets(); const matches = Object.entries(snippets).filter( ([name, data]) => name.toLowerCase().includes(query.toLowerCase()) || data.code.toLowerCase().includes(query.toLowerCase()) ); if (matches.length === 0) { console.log(chalk.yellow("No matching snippets found.")); return; } console.log(chalk.green(`Found ${matches.length} snippet(s):`)); matches.forEach(([name, data], i) => { const tags = data.tags?.length ? ` (${data.tags.join(", ")})` : ""; console.log(`${i + 1}. ${chalk.blue(name)}${tags}`); }); }); }