buildRequestFromArgs function

Future<Request> buildRequestFromArgs(
  1. List<String> args
)

Implementation

Future<http.Request> buildRequestFromArgs(List<String> args) async {
  final cliArgs = argparse.parseArguments(args);
  final cliArgsBodyParam = cliArgs.magicParameters.body;
  String? body;
  if (cliArgsBodyParam != null) {
    if (!stdin.hasTerminal) {
      // pipe input
      throw InvalidArgumentException(
          '@body cannot be specified when Pipe input is present');
    }
    body = await _readStreamAsString(
        File(cliArgsBodyParam).openRead().transform(utf8.decoder));
  } else if (!stdin.hasTerminal) {
    //pipe input
    body = await _readStreamAsString(stdin.transform(utf8.decoder));
  }

  return http.Request(
    cliArgs.method,
    cliArgs.path,
    cliArgs.headers,
    cliArgs.queryParameters,
    body,
  );
}