route method

Future<void> route(
  1. List<String> args, {
  2. required Logger logger,
})

Routes the user command arguments to the appropriate command handler class.

Implementation

Future<void> route(List<String> args, {required Logger logger}) async {
  if (args.isEmpty) {
    _printUsage(logger);
    return;
  }

  final commandName = args.first;
  final command = _commands[commandName];

  if (command == null) {
    logger.error('Unknown command: "$commandName"');
    _printUsage(logger);
    return;
  }

  final commandArgs = args.sublist(1);
  await command.run(commandArgs, logger: logger);
}