| 607 | vector<T>, |
| 608 | T>> |
| 609 | bool validate_arg(const cmdmap_t& cmdmap, |
| 610 | const arg_desc_t& desc, |
| 611 | const std::string_view name, |
| 612 | const std::string_view type, |
| 613 | std::ostream& os) |
| 614 | { |
| 615 | Value v; |
| 616 | try { |
| 617 | if (!cmd_getval(cmdmap, name, v)) { |
| 618 | if constexpr (is_vector) { |
| 619 | // an empty list is acceptable. |
| 620 | return true; |
| 621 | } else { |
| 622 | if (auto req = desc.find("req"); |
| 623 | req != end(desc) && req->second == "false") { |
| 624 | return true; |
| 625 | } else { |
| 626 | os << "missing required parameter: '" << name << "'"; |
| 627 | return false; |
| 628 | } |
| 629 | } |
| 630 | } |
| 631 | } catch (const bad_cmd_get& e) { |
| 632 | return false; |
| 633 | } |
| 634 | auto validate = [&](const T& value) { |
| 635 | if constexpr (is_same_v<std::string, T>) { |
| 636 | return validate_str_arg(value, type, desc, os); |
| 637 | } else if constexpr (is_same_v<int64_t, T> || |
| 638 | is_same_v<double, T>) { |
| 639 | return arg_in_range(value, desc, os); |
| 640 | } |
| 641 | }; |
| 642 | if constexpr(is_vector) { |
| 643 | return find_if_not(begin(v), end(v), validate) == end(v); |
| 644 | } else { |
| 645 | return validate(v); |
| 646 | } |
| 647 | } |
| 648 | } // anonymous namespace |
| 649 | |
| 650 | bool validate_cmd(const std::string& desc, |
nothing calls this directly
no test coverage detected