| 415 | void OSRunner::destroyProgressBar() const {} |
| 416 | |
| 417 | bool OSRunner::validateUserArguments(const std::vector<OSArgument>& script_arguments, const std::map<std::string, OSArgument>& user_arguments) { |
| 418 | bool result = true; |
| 419 | std::vector<WorkflowStepValue> stepValues; |
| 420 | for (const OSArgument& script_argument : script_arguments) { |
| 421 | if (script_argument.type().value() == OSArgumentType::Separator) { |
| 422 | // skip separators |
| 423 | continue; |
| 424 | } |
| 425 | auto it = user_arguments.find(script_argument.name()); |
| 426 | if (it == user_arguments.end()) { |
| 427 | // script_argument is not in user_arguments |
| 428 | // this is only okay for purely optional arguments |
| 429 | if (script_argument.required() || script_argument.hasDefaultValue()) { |
| 430 | registerError(fmt::format("Argument '{}' is required or has a default value, but is not in user_arguments.", script_argument.name())); |
| 431 | result = false; |
| 432 | } |
| 433 | } else { |
| 434 | // script_argument is in user_arguments |
| 435 | const OSArgument& user_argument = it->second; |
| 436 | |
| 437 | // check that names still match |
| 438 | if (user_argument.name() != script_argument.name()) { |
| 439 | registerWarning(fmt::format("User argument name '{}' does not match map key ", user_argument.name())); |
| 440 | } |
| 441 | |
| 442 | // check that types still match |
| 443 | if (user_argument.type() != script_argument.type()) { |
| 444 | registerError(fmt::format("User argument type {} does not match script argument type {}.", user_argument.type().valueName(), |
| 445 | script_argument.type().valueName())); |
| 446 | result = false; |
| 447 | } |
| 448 | |
| 449 | // check that we have values |
| 450 | if ((script_argument.required()) && !(user_argument.hasValue() || user_argument.hasDefaultValue())) { |
| 451 | registerError(fmt::format("Script argument '{}' is required, but the user argument does not have a value or default value set.", |
| 452 | script_argument.name())); |
| 453 | result = false; |
| 454 | } |
| 455 | |
| 456 | // check for default value mismatch |
| 457 | if (script_argument.hasDefaultValue() && !user_argument.hasDefaultValue()) { |
| 458 | registerWarning(fmt::format("Script argument '{}' has a default value, but the user-supplied version does not.", script_argument.name())); |
| 459 | } |
| 460 | if (!script_argument.hasDefaultValue() && user_argument.hasDefaultValue()) { |
| 461 | registerWarning( |
| 462 | fmt::format("Script argument '{}' does not have a default value, but the user-supplied version does.", script_argument.name())); |
| 463 | } |
| 464 | if (script_argument.hasDefaultValue() && user_argument.hasDefaultValue() && (user_argument.type() == script_argument.type())) { |
| 465 | std::stringstream ss; |
| 466 | ss << "The default value of script argument " << '\n' |
| 467 | << script_argument << '\n' |
| 468 | << "does not match that of the corresponding user argument " << '\n' |
| 469 | << user_argument << "."; |
| 470 | switch (script_argument.type().value()) { |
| 471 | case OSArgumentType::Boolean: |
| 472 | if (user_argument.defaultValueAsBool() != script_argument.defaultValueAsBool()) { |
| 473 | registerWarning(ss.str()); |
| 474 | } |