UNPKG

agentsqripts

Version:

Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems

32 lines (28 loc) 952 B
/** * @file Create a main function handler for CLI tools * @description Single responsibility: Generate standardized main function for CLI tools */ /** * Create a main function handler for CLI tools * @param {Function} analyzeFunction - The analysis function to run * @param {string} analysisType - Type of analysis for error messages */ function createMainHandler(analyzeFunction, analysisType) { return async function main() { const args = process.argv.slice(2); if (args.includes('--help') || args.length === 0) { // Show help will be handled by the specific tool return; } try { await analyzeFunction(args); } catch (error) { console.error(`\n❌ Error during ${analysisType} analysis:`, error.message); if (error.stack && process.env.DEBUG) { console.error('\nStack trace:', error.stack); } process.exit(1); } }; } module.exports = createMainHandler;