handle method

  1. @override
Future<void> handle(
  1. List<String> arguments
)

Handle the command line arguments to execute the given entry command.

Implementation

@override
Future<void> handle (List<String> arguments) async {
  await ioc.use<EnvironmentService>().load();

  ArgResults results = _parser.parse(arguments);
  final command = _commands.getOrFail(results.command?.name ?? 'help');

  if (command.arguments.isNotEmpty && results.arguments.length - 1 != command.arguments.length) {
    final params = command.arguments
      .map((e) => '<$e>')
      .join(', ');

    command.console.error('Please provide $params params.');
    return;
  }

  final params = {};
  for (int i = 0; i < command.arguments.length; i++) {
    params.putIfAbsent(command.arguments[i], () => results.arguments[i + 1]);
  }

  return await command.handle(params);
}