executeImpl method

  1. @override
Future executeImpl(
  1. Map<String, dynamic> params
)
override

Implement the actual tool logic

params are the validated parameters (never null here) Returns the result data to send in the response

Implementation

@override
Future<dynamic> executeImpl(Map<String, dynamic> params) async {
  final category = params['category'] as String?;
  final project = ServerPodLocator.getProject();

  if (project == null || !project.isValid) {
    return {'error': 'Not a valid ServerPod project'};
  }

  try {
    // Find bin directory
    final binDirectory = Directory.fromUri(Uri.file(project.rootPath).resolve('bin/'));
    if (!await binDirectory.exists()) {
      return {'error': 'No bin/ directory found'};
    }

    // Collect .dart files in bin directory (excluding this file itself)
    final dartFiles = binDirectory.listSync()
        .where((entity) =>
          entity is File &&
          entity.uri.pathSegments.last.endsWith('.dart') &&
          !entity.uri.pathSegments.last.contains('boost.dart') // Exclude main entry point
        )
        .cast<File>();

    final commands = <Map<String, dynamic>>[];
    final categories = <String>{};

    for (final file in dartFiles) {
      final command = await _parseCommandFile(file, project);
      if (command != null) {
        if (category == null || command['category'] == category) {
          commands.add(command);
          categories.add(command['category']);
        }
      }
    }

    return {
      'commands': commands,
      'categories': categories.toList(),
      'count': commands.length,
    };
  } catch (e) {
    return {'error': 'Failed to parse CLI commands: ${e.toString()}'};
  }
}