validatePath static method
Validates file path existence and accessibility.
Checks that the specified path exists and can be accessed for read/write operations.
Parameters:
path: File path to validatemustExist: Whether the path must already exist (default: true)
Returns: ValidationResult with the path or error details
Example:
final result = ArgumentValidator.validatePath('./lib/main.dart');
if (result.isValid) {
print('Valid path: ${result.value}');
} else {
print('Invalid path: ${result.error}');
}
Implementation
static ValidationResult<String> validatePath(String? path,
{bool mustExist = true}) {
if (path == null || path.isEmpty) {
return ValidationResult.error(
'Path is required',
suggestion: 'Provide a valid file or directory path',
examples: ['./path/to/file', '/absolute/path'],
);
}
// Additional path validation can be added here
// For now, return success - actual existence check should be done by caller
return ValidationResult.success(path);
}