commandArgument function

String? commandArgument(
  1. String command,
  2. String name
)

The value --name carries in command, however it was quoted.

Implementation

String? commandArgument(String command, String name) {
  final match = RegExp(
    '''(?:^|\\s)--$name(?:=|\\s+)(?:"([^"]+)"|'([^']+)'|(\\S+))''',
  ).firstMatch(command);
  if (match == null) return null;
  return match.group(1) ?? match.group(2) ?? match.group(3);
}