checkBooleanArg method

bool checkBooleanArg (
  1. String arg
)

Checks the argument is yes/no or equivalent, returning true/false if not boolean returns null

Implementation

bool checkBooleanArg(String arg) {
  Match match;
  final onOff =
      RegExp(r'^(on|t|true|y|yes)|(off|f|false|n|no)$', caseSensitive: false);

  if ((match = onOff.firstMatch(arg)) == null) {
    logger.error(
        ' unable to parse $arg as a boolean. Use one of on/t/true/y/yes/off/f/false/n/no');
    return null;
  }
  if (match[1] != null) return true;
  if (match[2] != null) return false;
  return null;
}