Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/util.cpp
Show First 20 Lines • Show All 312 Lines • ▼ Show 20 Lines | void Push(const RPCArg &arg, const size_t current_indent = 5, | ||||
outer_type == OuterType::OBJ) { | outer_type == OuterType::OBJ) { | ||||
left += "\"" + arg.m_name + "\": " + arg.m_type_str.at(0); | left += "\"" + arg.m_name + "\": " + arg.m_type_str.at(0); | ||||
} else { | } else { | ||||
left += outer_type == OuterType::OBJ | left += outer_type == OuterType::OBJ | ||||
? arg.ToStringObj(/* oneline */ false) | ? arg.ToStringObj(/* oneline */ false) | ||||
: arg.ToString(/* oneline */ false); | : arg.ToString(/* oneline */ false); | ||||
} | } | ||||
left += ","; | left += ","; | ||||
PushSection({left, arg.ToDescriptionString( | PushSection({left, arg.ToDescriptionString()}); | ||||
/* implicitly_required */ outer_type == | |||||
OuterType::ARR)}); | |||||
break; | break; | ||||
} | } | ||||
case RPCArg::Type::OBJ: | case RPCArg::Type::OBJ: | ||||
case RPCArg::Type::OBJ_USER_KEYS: { | case RPCArg::Type::OBJ_USER_KEYS: { | ||||
const auto right = | const auto right = outer_type == OuterType::NAMED_ARG | ||||
outer_type == OuterType::NAMED_ARG | |||||
? "" | ? "" | ||||
: arg.ToDescriptionString( | : arg.ToDescriptionString(); | ||||
/* implicitly_required */ outer_type == | |||||
OuterType::ARR); | |||||
PushSection({indent + "{", right}); | PushSection({indent + "{", right}); | ||||
for (const auto &arg_inner : arg.m_inner) { | for (const auto &arg_inner : arg.m_inner) { | ||||
Push(arg_inner, current_indent + 2, OuterType::OBJ); | Push(arg_inner, current_indent + 2, OuterType::OBJ); | ||||
} | } | ||||
if (arg.m_type != RPCArg::Type::OBJ) { | if (arg.m_type != RPCArg::Type::OBJ) { | ||||
PushSection({indent_next + "...", ""}); | PushSection({indent_next + "...", ""}); | ||||
} | } | ||||
PushSection( | PushSection( | ||||
{indent + "}" + | {indent + "}" + | ||||
(outer_type != OuterType::NAMED_ARG ? "," : ""), | (outer_type != OuterType::NAMED_ARG ? "," : ""), | ||||
""}); | ""}); | ||||
break; | break; | ||||
} | } | ||||
case RPCArg::Type::ARR: { | case RPCArg::Type::ARR: { | ||||
auto left = indent; | auto left = indent; | ||||
left += outer_type == OuterType::OBJ | left += outer_type == OuterType::OBJ | ||||
? "\"" + arg.m_name + "\": " | ? "\"" + arg.m_name + "\": " | ||||
: ""; | : ""; | ||||
left += "["; | left += "["; | ||||
const auto right = | const auto right = outer_type == OuterType::NAMED_ARG | ||||
outer_type == OuterType::NAMED_ARG | |||||
? "" | ? "" | ||||
: arg.ToDescriptionString( | : arg.ToDescriptionString(); | ||||
/* implicitly_required */ outer_type == | |||||
OuterType::ARR); | |||||
PushSection({left, right}); | PushSection({left, right}); | ||||
for (const auto &arg_inner : arg.m_inner) { | for (const auto &arg_inner : arg.m_inner) { | ||||
Push(arg_inner, current_indent + 2, OuterType::ARR); | Push(arg_inner, current_indent + 2, OuterType::ARR); | ||||
} | } | ||||
PushSection({indent_next + "...", ""}); | PushSection({indent_next + "...", ""}); | ||||
PushSection( | PushSection( | ||||
{indent + "]" + | {indent + "]" + | ||||
(outer_type != OuterType::NAMED_ARG ? "," : ""), | (outer_type != OuterType::NAMED_ARG ? "," : ""), | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | |||||
std::string RPCHelpMan::ToString() const { | std::string RPCHelpMan::ToString() const { | ||||
std::string ret; | std::string ret; | ||||
// Oneline summary | // Oneline summary | ||||
ret += m_name; | ret += m_name; | ||||
bool was_optional{false}; | bool was_optional{false}; | ||||
for (const auto &arg : m_args) { | for (const auto &arg : m_args) { | ||||
bool optional; | |||||
if (arg.m_fallback.which() == 1) { | |||||
optional = true; | |||||
} else { | |||||
optional = RPCArg::Optional::NO != | |||||
boost::get<RPCArg::Optional>(arg.m_fallback); | |||||
} | |||||
ret += " "; | ret += " "; | ||||
if (arg.m_optional) { | if (optional) { | ||||
if (!was_optional) { | if (!was_optional) { | ||||
ret += "( "; | ret += "( "; | ||||
} | } | ||||
was_optional = true; | was_optional = true; | ||||
} else { | } else { | ||||
if (was_optional) { | if (was_optional) { | ||||
ret += ") "; | ret += ") "; | ||||
} | } | ||||
Show All 34 Lines | std::string RPCHelpMan::ToString() const { | ||||
ret += m_results.ToDescriptionString(); | ret += m_results.ToDescriptionString(); | ||||
// Examples | // Examples | ||||
ret += m_examples.ToDescriptionString(); | ret += m_examples.ToDescriptionString(); | ||||
return ret; | return ret; | ||||
} | } | ||||
std::string RPCArg::ToDescriptionString(const bool implicitly_required) const { | std::string RPCArg::ToDescriptionString() const { | ||||
std::string ret; | std::string ret; | ||||
ret += "("; | ret += "("; | ||||
if (m_type_str.size() != 0) { | if (m_type_str.size() != 0) { | ||||
ret += m_type_str.at(1); | ret += m_type_str.at(1); | ||||
} else { | } else { | ||||
switch (m_type) { | switch (m_type) { | ||||
case Type::STR_HEX: | case Type::STR_HEX: | ||||
case Type::STR: { | case Type::STR: { | ||||
Show All 20 Lines | if (m_type_str.size() != 0) { | ||||
case Type::ARR: { | case Type::ARR: { | ||||
ret += "json array"; | ret += "json array"; | ||||
break; | break; | ||||
} | } | ||||
// no default case, so the compiler can warn about missing cases | // no default case, so the compiler can warn about missing cases | ||||
} | } | ||||
} | } | ||||
if (!implicitly_required) { | if (m_fallback.which() == 1) { | ||||
ret += ", "; | ret += ", optional, default=" + boost::get<std::string>(m_fallback); | ||||
if (m_optional) { | |||||
ret += "optional"; | |||||
if (!m_default_value.empty()) { | |||||
ret += ", default=" + m_default_value; | |||||
} else { | } else { | ||||
// TODO enable this assert, when all optional parameters have | switch (boost::get<RPCArg::Optional>(m_fallback)) { | ||||
// their default value documented | case RPCArg::Optional::OMITTED: { | ||||
// assert(false); | // nothing to do. Element is treated as if not present and has | ||||
// no default value | |||||
break; | |||||
} | } | ||||
} else { | case RPCArg::Optional::OMITTED_NAMED_ARG: { | ||||
ret += "required"; | ret += ", optional"; // Default value is "null" | ||||
// Default value is ignored, and must not be present | break; | ||||
assert(m_default_value.empty()); | } | ||||
case RPCArg::Optional::NO: { | |||||
ret += ", required"; | |||||
break; | |||||
} | |||||
// no default case, so the compiler can warn about missing cases | |||||
} | } | ||||
} | } | ||||
ret += ")"; | ret += ")"; | ||||
ret += m_description.empty() ? "" : " " + m_description; | ret += m_description.empty() ? "" : " " + m_description; | ||||
return ret; | return ret; | ||||
} | } | ||||
std::string RPCArg::ToStringObj(const bool oneline) const { | std::string RPCArg::ToStringObj(const bool oneline) const { | ||||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |