public static BenchmarkConfig parseCommandLine()

in httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/CommandLineUtils.java [143:247]


    public static BenchmarkConfig parseCommandLine(final CommandLine cmd) {
        final BenchmarkConfig.Builder builder = new BenchmarkConfig.Builder();
        if (cmd.hasOption('n')) {
            final String s = cmd.getOptionValue('n');
            try {
                builder.setRequests(Integer.parseInt(s));
            } catch (final NumberFormatException ex) {
                printError("Invalid number of requests: " + s);
            }
        }

        if (cmd.hasOption('c')) {
            final String s = cmd.getOptionValue('c');
            try {
                builder.setConcurrencyLevel(Integer.parseInt(s));
            } catch (final NumberFormatException ex) {
                printError("Invalid number for concurrency: " + s);
            }
        }

        if (cmd.hasOption('t')) {
            final String t = cmd.getOptionValue('t');
            try {
                builder.setTimeLimit(TimeValue.ofSeconds(Integer.parseInt(t)));
            } catch (final NumberFormatException ex) {
                printError("Invalid time limit: " + t);
            }
        }

        if (cmd.hasOption('s')) {
            final String s = cmd.getOptionValue('s');
            try {
                builder.setSocketTimeout(Timeout.ofMilliseconds(Integer.parseInt(s)));
            } catch (final NumberFormatException ex) {
                printError("Invalid socket timeout: " + s);
            }
        }

        if (cmd.hasOption('p')) {
            final File file = new File(cmd.getOptionValue('p'));
            if (!file.exists()) {
                printError("File not found: " + file);
            }
            builder.setPayloadFile(file);
        }

        if (cmd.hasOption('T')) {
            builder.setContentType(ContentType.parse(cmd.getOptionValue('T')));
        }

        if (cmd.hasOption('v')) {
            final String s = cmd.getOptionValue('v');
            try {
                builder.setVerbosity(Integer.parseInt(s));
            } catch (final NumberFormatException ex) {
                printError("Invalid verbosity level: " + s);
            }
        }

        if (cmd.hasOption('i')) {
            builder.setHeadInsteadOfGet(true);
        }

        if (cmd.hasOption('H')) {
            final String headerStr = cmd.getOptionValue('H');
            builder.setHeaders(headerStr.split(","));
        }

        if (cmd.hasOption('k')) {
            builder.setKeepAlive(true);
        }

        if (cmd.hasOption('m')) {
            builder.setMethod(cmd.getOptionValue('m'));
        } else if (cmd.hasOption('p')) {
            builder.setMethod(Method.POST.name());
        }

        if (cmd.hasOption('u')) {
            builder.setUseChunking(true);
        }

        if (cmd.hasOption('x')) {
            builder.setUseExpectContinue(true);
        }

        if (cmd.hasOption('g')) {
            builder.setUseAcceptGZip(true);
        }

        if (cmd.hasOption('2')) {
            builder.setForceHttp2(true);
        }

        final String[] cmdargs = cmd.getArgs();
        if (cmdargs.length > 0) {
            try {
                builder.setUri(new URI(cmdargs[0]));
            } catch (final URISyntaxException e) {
                printError("Invalid request URI: " + cmdargs[0]);
            }
        }

        return builder.build();
    }