MCPcopy Create free account
hub / github.com/ceph/ceph / validate_arg

Function validate_arg

src/common/cmdparse.cc:609–647  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

607 vector<T>,
608 T>>
609bool 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
650bool validate_cmd(const std::string& desc,

Callers

nothing calls this directly

Calls 7

validate_str_argFunction · 0.85
arg_in_rangeFunction · 0.85
cmd_getvalFunction · 0.70
endFunction · 0.50
beginFunction · 0.50
validateFunction · 0.50
findMethod · 0.45

Tested by

no test coverage detected