rejectForeignOptions function

void rejectForeignOptions(
  1. String role,
  2. ArgResults args
)

Rejects options belonging to the other role.

The service parser accepts the union of both roles' options, so nothing stops you writing service install node --cert x. Silently ignoring it would install a node that quietly dropped the flag you asked for.

Implementation

void rejectForeignOptions(String role, ArgResults args) {
  final foreign = role == 'hub' ? _nodeOnlyOptions : _hubOnlyOptions;
  final passed = foreign.where(args.wasParsed).toList()..sort();
  if (passed.isEmpty) return;
  final names = passed.map((o) => '--$o').join(', ');
  final other = role == 'hub' ? 'node' : 'hub';
  throw CliError(
    passed.length == 1
        ? '$names is a $other option; not valid for role "$role"'
        : '$names are $other options; not valid for role "$role"',
  );
}