run method

  1. @override
Future<int> run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
Future<int> run() async {
  final rootPath = argResults?['root'] as String? ?? fs.currentDirectory.path;
  final root = fs.directory(rootPath);

  if (!root.existsSync()) {
    logger.err('No such directory: $rootPath');

    return 1;
  }

  final services = const ServiceDiscovery().find(root);

  if (services.isEmpty) {
    logger.err(
      'No Revali services found under $rootPath.\n'
      'A service is a package with a routes/ directory that depends on '
      'revali_router.',
    );

    return 1;
  }

  if (argResults?['paths'] as bool? ?? false) {
    for (final service in services) {
      io.stdout.writeln(service.relativePath);
    }

    return 0;
  }

  logger.info('${services.length} service(s)\n');

  final width = services
      .map((s) => s.name.length)
      .reduce((a, b) => a > b ? a : b);

  for (final service in services) {
    final built = service.hasDockerfile ? '' : '  (no Dockerfile yet)';

    logger.info(
      '  ${service.name.padRight(width)}  ${service.relativePath}$built',
    );
  }

  return 0;
}