validateCliOptDefs method

void validateCliOptDefs(
  1. List<String> longNames,
  2. List<String> longSubNames,
  3. List<String> shortNames,
  4. List<String> shortSubNames,
)

Checks there is no long option or long sub-option consisting of short options and short sub-options
Throws an exception when such match found
Useful solely for the unit testing or a rare sanity check, as in release mode, the parser simply prefers long options over the bundled short ones

Implementation

void validateCliOptDefs(List<String> longNames, List<String> longSubNames,
    List<String> shortNames, List<String> shortSubNames) {
  final allLongNames = <String>[...longNames, ...longSubNames];
  final allShortNames = <String>[...shortNames, ...shortSubNames];

  for (final longName in allLongNames) {
    var isFound = true;

    for (final shortName in longName.split('')) {
      if (!allShortNames.contains(shortName)) {
        isFound = false;
        break;
      }
    }
    if (isFound) {
      throw CliOptLongNameAsBundleException(longName);
    }
  }
}