feat(scripts): Add fuzzy search and type filtering for community scripts; improve scripts CLI output and cache handling

This commit is contained in:
2025-10-29 01:18:28 +00:00
parent 0e7d416048
commit 90c5f07be4
6 changed files with 82 additions and 30 deletions
+32 -19
View File
@@ -140,17 +140,8 @@ export const runCli = async () => {
logger.log('info', '');
try {
// Get current version from deno.json
const denoJsonPath = plugins.path.join(paths.packageDir, 'deno.json');
let currentVersion = '1.1.0'; // fallback
try {
const denoJsonContent = await Deno.readTextFile(denoJsonPath);
const denoJson = JSON.parse(denoJsonContent);
currentVersion = denoJson.version || currentVersion;
} catch {
// Use fallback version
}
// Get current version from compile-time imported deno.json
const currentVersion = denoConfig.version;
// Fetch latest version from Gitea API
const apiUrl = 'https://code.foss.global/api/v1/repos/serve.zone/moxytool/releases/latest';
@@ -289,28 +280,50 @@ export const runCli = async () => {
if (!query) {
logger.log('error', 'Please provide a search query');
logger.log('info', 'Usage: moxytool scripts search <query>');
logger.log('info', 'Usage: moxytool scripts search <query> [--filter type:vm]');
logger.log('info', 'Filters: type:vm, type:ct, type:pve, type:addon');
return;
}
const results = scriptIndex.search(query as string);
// Parse filter option
let typeFilter: string | undefined;
if (argvArg.filter) {
const filterString = argvArg.filter as string;
if (filterString.startsWith('type:')) {
typeFilter = filterString.substring(5);
}
}
const results = scriptIndex.search(query as string, typeFilter);
if (results.length === 0) {
logger.log('warn', `No scripts found matching "${query}"`);
const filterMsg = typeFilter ? ` (filtered by type:${typeFilter})` : '';
logger.log('warn', `No scripts found matching "${query}"${filterMsg}`);
return;
}
logger.log('info', `Found ${results.length} script(s) matching "${query}":`);
const filterMsg = typeFilter ? ` \x1b[2m(filtered by type:${typeFilter})\x1b[0m` : '';
logger.log('info', `Found ${results.length} script(s) matching "\x1b[1m${query}\x1b[0m"${filterMsg}:`);
logger.log('info', '');
results.forEach(script => {
logger.log('info', `${script.slug} (${script.type})`);
logger.log('info', ` ${script.name}`);
logger.log('info', ` ${script.description.substring(0, 80)}...`);
const slug = script.slug || 'unknown';
const description = script.description ? script.description.substring(0, 100) : 'No description available';
// Type badge with colors
let typeBadge = '';
if (script.type === 'ct') typeBadge = '\x1b[36m[LXC]\x1b[0m';
else if (script.type === 'vm') typeBadge = '\x1b[35m[VM]\x1b[0m';
else if (script.type === 'pve') typeBadge = '\x1b[33m[PVE]\x1b[0m';
else typeBadge = `\x1b[2m[${script.type}]\x1b[0m`;
logger.log('info', `\x1b[1m\x1b[36m►\x1b[0m \x1b[1m${slug}\x1b[0m ${typeBadge}`);
logger.log('info', ` \x1b[2m${script.name}\x1b[0m`);
logger.log('info', ` ${description}${script.description && script.description.length > 100 ? '...' : ''}`);
logger.log('info', '');
});
logger.log('info', 'Use "moxytool scripts info <slug>" for more details');
logger.log('info', '\x1b[2mUse "moxytool scripts info <slug>" for more details\x1b[0m');
break;
}