@@ -891,51 +891,62 @@ static bool common_params_parse_ex(int argc, char ** argv, common_params_context
891891 };
892892
893893 for (int i = 1 ; i < argc; i++) {
894- const std::string arg_prefix = " --" ;
894+ const std::string arg_prefix = " --" ;
895895
896- std::string arg = argv[i];
897- if (arg.compare (0 , arg_prefix.size (), arg_prefix) == 0 ) {
898- std::replace (arg.begin (), arg.end (), ' _' , ' -' );
899- }
900- if (arg_to_options. find (arg) == arg_to_options. end ()) {
901- throw std::invalid_argument ( string_format ( " error: invalid argument: %s " , arg. c_str ()));
902- }
903- auto opt = *arg_to_options[arg];
904- if (opt. has_value_from_env () ) {
905- fprintf (stderr, " warn: %s environment variable is set, but will be overwritten by command line argument %s \n " , opt. env , arg. c_str ());
896+ std::string arg = argv[i];
897+ if (arg.compare (0 , arg_prefix.size (), arg_prefix) == 0 ) {
898+ std::replace (arg.begin (), arg.end (), ' _' , ' -' );
899+ }
900+
901+ // Skip --parse-layer and its value(s)
902+ if (arg == " --parse-layer " ) {
903+ // Assuming --parse-layer takes exactly 1 argument
904+ if (i + 1 < argc ) {
905+ i++; // skip the next value as well
906906 }
907- try {
908- if (opt.handler_void ) {
909- opt.handler_void (params);
910- continue ;
911- }
907+ continue ;
908+ }
912909
913- // arg with single value
914- check_arg (i);
915- std::string val = argv[++i];
916- if (opt.handler_int ) {
917- opt.handler_int (params, std::stoi (val));
918- continue ;
919- }
920- if (opt.handler_string ) {
921- opt.handler_string (params, val);
922- continue ;
923- }
910+ if (arg_to_options.find (arg) == arg_to_options.end ()) {
911+ throw std::invalid_argument (string_format (" error: invalid argument: %s" , arg.c_str ()));
912+ }
924913
925- // arg with 2 values
926- check_arg (i);
927- std::string val2 = argv[++i];
928- if (opt.handler_str_str ) {
929- opt.handler_str_str (params, val, val2);
930- continue ;
931- }
932- } catch (std::exception & e) {
933- throw std::invalid_argument (string_format (
934- " error while handling argument \" %s\" : %s\n\n "
935- " usage:\n %s\n\n to show complete usage, run with -h" ,
936- arg.c_str (), e.what (), arg_to_options[arg]->to_string ().c_str ()));
937- }
914+ auto opt = *arg_to_options[arg];
915+ if (opt.has_value_from_env ()) {
916+ fprintf (stderr, " warn: %s environment variable is set, but will be overwritten by command line argument %s\n " , opt.env , arg.c_str ());
917+ }
918+ try {
919+ if (opt.handler_void ) {
920+ opt.handler_void (params);
921+ continue ;
922+ }
923+
924+ // arg with single value
925+ check_arg (i);
926+ std::string val = argv[++i];
927+ if (opt.handler_int ) {
928+ opt.handler_int (params, std::stoi (val));
929+ continue ;
930+ }
931+ if (opt.handler_string ) {
932+ opt.handler_string (params, val);
933+ continue ;
934+ }
935+
936+ // arg with 2 values
937+ check_arg (i);
938+ std::string val2 = argv[++i];
939+ if (opt.handler_str_str ) {
940+ opt.handler_str_str (params, val, val2);
941+ continue ;
942+ }
943+ } catch (std::exception & e) {
944+ throw std::invalid_argument (string_format (
945+ " error while handling argument \" %s\" : %s\n\n "
946+ " usage:\n %s\n\n to show complete usage, run with -h" ,
947+ arg.c_str (), e.what (), arg_to_options[arg]->to_string ().c_str ()));
938948 }
949+ }
939950
940951 postprocess_cpu_params (params.cpuparams , nullptr );
941952 postprocess_cpu_params (params.cpuparams_batch , ¶ms.cpuparams );
0 commit comments