NOLINTNEXTLINE(misc-no-recursion)
| 995 | |
| 996 | // NOLINTNEXTLINE(misc-no-recursion) |
| 997 | void RPCResult::ToSections(Sections& sections, const OuterType outer_type, const int current_indent) const |
| 998 | { |
| 999 | // Indentation |
| 1000 | const std::string indent(current_indent, ' '); |
| 1001 | const std::string indent_next(current_indent + 2, ' '); |
| 1002 | |
| 1003 | // Elements in a JSON structure (dictionary or array) are separated by a comma |
| 1004 | const std::string maybe_separator{outer_type != OuterType::NONE ? "," : ""}; |
| 1005 | |
| 1006 | // The key name if recursed into a dictionary |
| 1007 | const std::string maybe_key{ |
| 1008 | outer_type == OuterType::OBJ ? |
| 1009 | "\"" + this->m_key_name + "\" : " : |
| 1010 | ""}; |
| 1011 | |
| 1012 | // Format description with type |
| 1013 | const auto Description = [&](const std::string& type) { |
| 1014 | return "(" + type + (this->m_optional ? ", optional" : "") + ")" + |
| 1015 | (this->m_description.empty() ? "" : " " + this->m_description); |
| 1016 | }; |
| 1017 | |
| 1018 | // Ensure at least one visible field exists when elision is used |
| 1019 | const auto elision_has_description{[](const std::vector<RPCResult>& inner) { |
| 1020 | return std::ranges::any_of(inner, [](const auto& res) { |
| 1021 | return !std::holds_alternative<HelpElisionSkip>(res.m_opts.print_elision); |
| 1022 | }); |
| 1023 | }}; |
| 1024 | |
| 1025 | if (const auto* text = std::get_if<std::string>(&m_opts.print_elision)) { |
| 1026 | sections.PushSection({indent + "..." + maybe_separator, *text}); |
| 1027 | return; |
| 1028 | } |
| 1029 | if (std::holds_alternative<HelpElisionSkip>(m_opts.print_elision)) { |
| 1030 | return; |
| 1031 | } |
| 1032 | |
| 1033 | switch (m_type) { |
| 1034 | case Type::ANY: { |
| 1035 | NONFATAL_UNREACHABLE(); // Only for testing |
| 1036 | } |
| 1037 | case Type::NONE: { |
| 1038 | sections.PushSection({indent + "null" + maybe_separator, Description("json null")}); |
| 1039 | return; |
| 1040 | } |
| 1041 | case Type::STR: { |
| 1042 | sections.PushSection({indent + maybe_key + "\"str\"" + maybe_separator, Description("string")}); |
| 1043 | return; |
| 1044 | } |
| 1045 | case Type::STR_AMOUNT: { |
| 1046 | sections.PushSection({indent + maybe_key + "n" + maybe_separator, Description("numeric")}); |
| 1047 | return; |
| 1048 | } |
| 1049 | case Type::STR_HEX: { |
| 1050 | sections.PushSection({indent + maybe_key + "\"hex\"" + maybe_separator, Description("string")}); |
| 1051 | return; |
| 1052 | } |
| 1053 | case Type::NUM: { |
| 1054 | sections.PushSection({indent + maybe_key + "n" + maybe_separator, Description("numeric")}); |
no test coverage detected