This commit is contained in:
pablof7z
2025-04-09 11:45:30 +01:00
parent 630ed0cbd0
commit b258f49201
8 changed files with 134 additions and 48 deletions

View File

@@ -1,25 +1,37 @@
import { Command } from 'commander';
import { Command } from "commander";
import {
formatPartialMatches,
formatSnippets,
getSnippets
} from '../lib/nostr/snippets.js';
getSnippets,
} from "../lib/nostr/snippets.js";
export function registerFindSnippetsCommand(program: Command): void {
program
.command('find-snippets')
.description('Find code snippets with optional filters')
.option('--limit <number>', 'Maximum number of snippets to return')
.option('--languages <list>', 'Comma-separated list of languages to filter by')
.option('--tags <list>', 'Comma-separated list of tags to filter by')
.option('--authors <list>', 'Comma-separated list of authors to filter by')
.command("find-snippets")
.description("Find code snippets with optional filters")
.option("--limit <number>", "Maximum number of snippets to return")
.option(
"--languages <list>",
"Comma-separated list of languages to filter by"
)
.option("--tags <list>", "Comma-separated list of tags to filter by")
.option(
"--authors <list>",
"Comma-separated list of authors to filter by"
)
.action(async (options) => {
try {
// Parse options
const limit = options.limit ? parseInt(options.limit, 10) : undefined;
const languages = options.languages ? options.languages.split(',') : undefined;
const tags = options.tags ? options.tags.split(',') : undefined;
const authors = options.authors ? options.authors.split(',') : undefined;
const limit = options.limit
? parseInt(options.limit, 10)
: undefined;
const languages = options.languages
? options.languages.split(",")
: undefined;
const tags = options.tags ? options.tags.split(",") : undefined;
const authors = options.authors
? options.authors.split(",")
: undefined;
const { snippets, otherSnippets } = await getSnippets({
limit,
@@ -29,10 +41,13 @@ export function registerFindSnippetsCommand(program: Command): void {
});
if (snippets.length === 0) {
console.log("No code snippets found matching the criteria.");
console.log(
"No code snippets found matching the criteria."
);
} else {
const formattedSnippets = formatSnippets(snippets);
const partialMatchesText = formatPartialMatches(otherSnippets);
const partialMatchesText =
formatPartialMatches(otherSnippets);
console.log(
`Found ${snippets.length} code snippets:\n\n${formattedSnippets}${partialMatchesText}`
);
@@ -42,4 +57,4 @@ export function registerFindSnippetsCommand(program: Command): void {
process.exit(1);
}
});
}
}

View File

@@ -3,6 +3,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
import type { Command } from "commander";
import { readConfig } from "../config.js";
import { addCreatePubkeyCommand } from "../logic/create-pubkey.js";
import { addDepositCommand } from "../logic/deposit.js";
import { addFetchSnippetByIdCommand } from "../logic/fetch_snippet_by_id.js";
import { addFindSnippetsCommand } from "../logic/find_snippets.js";
import { addFindUserCommand } from "../logic/find_user.js";
@@ -29,6 +30,7 @@ const commandMap: Record<string, CommandFunction> = {
"fetch-snippet-by-id": addFetchSnippetByIdCommand,
zap: addZapCommand,
"wallet-balance": addWalletBalanceCommand,
deposit: addDepositCommand,
};
// Global server instance
@@ -87,4 +89,5 @@ export function registerMcpCommands(server: McpServer) {
addZapCommand(server);
addWalletBalanceCommand(server);
}
addDepositCommand(server);
}