MCPcopy Create free account
hub / github.com/BrunoLevy/geogram / parse_internal

Function parse_internal

src/lib/geogram/basic/command_line.cpp:350–408  ·  view source on GitHub ↗

* \brief Parses the command line arguments * \details This analyzes command line arguments passed to the main() * program in \p argc and \p argv. Arguments not matching program * options declared with declare_arg() are stored in output vector \p * unparsed_args. * \param[in] argc number of arguments passed to main() * \param[in] argv array of command line arguments pa

Source from the content-addressed store, hash-verified

348 * \retval false otherwise
349 */
350 bool parse_internal(
351 int argc, char** argv, std::vector<std::string>& unparsed_args
352 ) {
353 geo_argc = argc;
354 geo_argv = argv;
355
356 parse_config_file(argc, argv);
357
358 bool ok = true;
359 desc_->argv0 = argv[0];
360 unparsed_args.clear();
361
362 for(int i = 1; i < argc; i++) {
363 std::vector<std::string> parsed_arg;
364 String::split_string(argv[i], '=', parsed_arg);
365 if(parsed_arg.size() != 2) {
366 unparsed_args.push_back(argv[i]);
367 } else {
368 if(
369 String::string_starts_with(parsed_arg[0], "dbg:") ||
370 desc_->args.find(parsed_arg[0]) != desc_->args.end()
371 ) {
372 if(!set_arg(parsed_arg[0], parsed_arg[1])) {
373 ok = false;
374 }
375 } else {
376
377 std::vector<std::string> matches;
378 for( auto& it : desc_->args) {
379 if(arg_matches(parsed_arg[0], it.first)) {
380 matches.push_back(it.first);
381 }
382 }
383
384 if(matches.size() == 1) {
385 if(!set_arg(matches[0], parsed_arg[1])) {
386 ok = false;
387 }
388 } else if(matches.size() >= 2) {
389 ok = false;
390 Logger::instance()->set_quiet(false);
391 Logger::err("CmdLine")
392 << "Argument is ambiguous: " << argv[i]
393 << std::endl
394 << "Possible matches: "
395 << String::join_strings(matches, ' ')
396 << std::endl;
397 } else {
398 ok = false;
399 Logger::instance()->set_quiet(false);
400 Logger::err("CmdLine")
401 << "Invalid argument: " << parsed_arg[0]
402 << std::endl;
403 }
404 }
405 }
406 }
407 return ok;

Callers 1

parseFunction · 0.85

Calls 13

parse_config_fileFunction · 0.85
split_stringFunction · 0.85
string_starts_withFunction · 0.85
arg_matchesFunction · 0.85
join_stringsFunction · 0.85
set_quietMethod · 0.80
set_argFunction · 0.70
instanceFunction · 0.50
clearMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected