MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / common_params_parse_ex

Function common_params_parse_ex

common/arg.cpp:427–644  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

425//
426
427static bool common_params_parse_ex(int argc, char ** argv, common_params_context & ctx_arg) {
428 common_params & params = ctx_arg.params;
429
430 // setup log directly from params.verbosity: see tools/cli/cli.cpp
431 common_log_set_verbosity_thold(params.verbosity);
432
433 std::unordered_map<std::string, std::pair<common_arg *, bool>> arg_to_options;
434 for (auto & opt : ctx_arg.options) {
435 for (const auto & arg : opt.args) {
436 arg_to_options[arg] = {&opt, /* is_positive */ true};
437 }
438 for (const auto & arg : opt.args_neg) {
439 arg_to_options[arg] = {&opt, /* is_positive */ false};
440 }
441 }
442
443 // handle environment variables
444 for (auto & opt : ctx_arg.options) {
445 std::string value;
446 if (opt.get_value_from_env(value)) {
447 try {
448 if (opt.handler_void && is_truthy(value)) {
449 opt.handler_void(params);
450 }
451 if (opt.handler_int) {
452 opt.handler_int(params, std::stoi(value));
453 }
454 if (opt.handler_bool) {
455 opt.handler_bool(params, parse_bool_value(value));
456 }
457 if (opt.handler_string) {
458 opt.handler_string(params, value);
459 continue;
460 }
461 } catch (std::exception & e) {
462 throw std::invalid_argument(string_format(
463 "error while handling environment variable \"%s\": %s\n\n", opt.env, e.what()));
464 }
465 }
466 }
467
468 // handle command line arguments
469 auto check_arg = [&](int i) {
470 if (i+1 >= argc) {
471 throw std::invalid_argument("expected value for argument");
472 }
473 };
474
475 auto parse_cli_args = [&]() {
476 std::set<std::string> seen_args;
477
478 for (int i = 1; i < argc; i++) {
479 const std::string arg_prefix = "--";
480
481 std::string arg = argv[i];
482 if (arg.compare(0, arg_prefix.size(), arg_prefix) == 0) {
483 std::replace(arg.begin(), arg.end(), '_', '-');
484 }

Callers 1

common_params_parseFunction · 0.85

Calls 15

parse_bool_valueFunction · 0.85
postprocess_cpu_paramsFunction · 0.85
string_process_escapesFunction · 0.85
get_value_from_envMethod · 0.80
endMethod · 0.80
findMethod · 0.80

Tested by

no test coverage detected