buildInvocationParams function

List buildInvocationParams(
  1. List positionalArguments, [
  2. List<String>? optionsNames
])

Implementation

List buildInvocationParams(List<dynamic> positionalArguments,
    [List<String>? optionsNames]) {
  List argsList = [];
  argsList.addAll(positionalArguments);
  Map? options = {};
  if (argsList.length > 1 && argsList.last is Map) {
    if (optionsNames == null) {
      options = argsList.removeLast();
    } else {
      Map lastArgument = argsList.last;
      bool isOptions = true;
      lastArgument.forEach((key, _) {
        if (!optionsNames.contains(key)) {
          isOptions = false;
        }
      });
      if (isOptions) {
        options = argsList.removeLast();
      }
    }
  }
  List invocationParams = [argsList];
  if (options!.isNotEmpty) {
    invocationParams.add(options);
  }
  return invocationParams;
}