Files
ruflo/src/cli/validation-helper.js
T
rUvandClaude 63d391e10b 🚀 Release: Claude Flow v2.0.0-alpha.62
## 🔒 Security Fixes
- CRITICAL: Removed vulnerable pkg dependency (GHSA-22r3-9w55-cj54)
- Replaced with secure @vercel/ncc alternative
- Security score improved from 55/100 to 75/100
- All npm audit vulnerabilities resolved (0 vulnerabilities)

## 🚀 Infrastructure Improvements
- Re-enabled ALL CI/CD security gates with strict enforcement
- Fixed Jest configuration and test infrastructure
- Fixed 18 TypeScript test files with import issues
- Created comprehensive test utilities

## 🛠️ Code Quality
- Fixed 145 ESLint errors (16% reduction)
- Fixed 15 critical TypeScript errors
- Added development tooling configs

## 📚 Documentation
- Created security audit report
- Created fix summary documentation
- Created functionality review
- Updated GitHub issue #362

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-18 13:35:41 +00:00

114 lines
2.7 KiB
JavaScript

/**
* CLI Parameter Validation Helper
* Provides standardized error messages for invalid parameters
*/
import { HelpFormatter } from './help-formatter.js';
export class ValidationHelper {
/**
* Validate enum parameter
*/
static validateEnum(value, paramName, validOptions, commandPath) {
if (!validOptions.includes(value)) {
console.error(
HelpFormatter.formatValidationError(value, paramName, validOptions, commandPath),
);
process.exit(1);
}
}
/**
* Validate numeric parameter
*/
static validateNumber(value, paramName, min, max, commandPath) {
const num = parseInt(value, 10);
if (isNaN(num)) {
console.error(
HelpFormatter.formatError(
`'${value}' is not a valid number for ${paramName}.`,
commandPath || 'claude-flow',
),
);
process.exit(1);
}
if (min !== undefined && num < min) {
console.error(
HelpFormatter.formatError(
`${paramName} must be at least ${min}. Got: ${num}`,
commandPath || 'claude-flow',
),
);
process.exit(1);
}
if (max !== undefined && num > max) {
console.error(
HelpFormatter.formatError(
`${paramName} must be at most ${max}. Got: ${num}`,
commandPath || 'claude-flow',
),
);
process.exit(1);
}
return num;
}
/**
* Validate required parameter
*/
static validateRequired(value, paramName, commandPath) {
if (!value || (typeof value === 'string' && value.trim() === '')) {
console.error(
HelpFormatter.formatError(
`Missing required parameter: ${paramName}`,
commandPath || 'claude-flow',
),
);
process.exit(1);
}
}
/**
* Validate file path exists
*/
static async validateFilePath(path, paramName, commandPath) {
try {
const fs = await import('fs/promises');
await fs.access(path);
} catch (error) {
console.error(
HelpFormatter.formatError(
`File not found for ${paramName}: ${path}`,
commandPath || 'claude-flow',
),
);
process.exit(1);
}
}
/**
* Validate boolean flag
*/
static validateBoolean(value, paramName, commandPath) {
const lowerValue = value.toLowerCase();
if (lowerValue === 'true' || lowerValue === '1' || lowerValue === 'yes') {
return true;
}
if (lowerValue === 'false' || lowerValue === '0' || lowerValue === 'no') {
return false;
}
console.error(
HelpFormatter.formatError(
`'${value}' is not a valid boolean for ${paramName}. Use: true, false, yes, no, 1, or 0.`,
commandPath || 'claude-flow',
),
);
process.exit(1);
}
}