requireRole function

String requireRole(
  1. ArgResults args
)

Reads and validates the hub|node role positional from args.

Implementation

String requireRole(ArgResults args) {
  final rest = args.rest;
  if (rest.isEmpty) throw CliError('specify a role: hub or node');
  final role = rest.first;
  if (!serviceRoles.contains(role)) {
    throw CliError("unknown role '$role' (expected: hub or node)");
  }
  if (rest.length > 1) {
    throw CliError('unexpected arguments: ${rest.skip(1).join(' ')}');
  }
  return role;
}