Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/util.cpp
Show First 20 Lines • Show All 248 Lines • ▼ Show 20 Lines | std::string ToString() const { | ||||
} | } | ||||
ret += right; | ret += right; | ||||
ret += "\n"; | ret += "\n"; | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
}; | }; | ||||
RPCHelpMan::RPCHelpMan(std::string name, std::string description, | |||||
std::vector<RPCArg> args, RPCResults results, | |||||
RPCExamples examples) | |||||
: m_name{std::move(name)}, m_description{std::move(description)}, | |||||
m_args{std::move(args)}, m_results{std::move(results)}, | |||||
m_examples{std::move(examples)} { | |||||
std::set<std::string> named_args; | |||||
for (const auto &arg : m_args) { | |||||
// Should have unique named arguments | |||||
assert(named_args.insert(arg.m_name).second); | |||||
} | |||||
} | |||||
std::string RPCResults::ToDescriptionString() const { | |||||
std::string result; | |||||
for (const auto &r : m_results) { | |||||
if (r.m_cond.empty()) { | |||||
result += "\nResult:\n"; | |||||
} else { | |||||
result += "\nResult (" + r.m_cond + "):\n"; | |||||
} | |||||
result += r.m_result; | |||||
} | |||||
return result; | |||||
} | |||||
std::string RPCExamples::ToDescriptionString() const { | |||||
return m_examples.empty() ? m_examples : "\nExamples:\n" + m_examples; | |||||
} | |||||
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 is_optional{false}; | bool is_optional{false}; | ||||
for (const auto &arg : m_args) { | for (const auto &arg : m_args) { | ||||
ret += " "; | ret += " "; | ||||
Show All 40 Lines | for (size_t i{0}; i < m_args.size(); ++i) { | ||||
sections.m_max_pad = std::max(sections.m_max_pad, | sections.m_max_pad = std::max(sections.m_max_pad, | ||||
sections.m_sections.back().m_left.size()); | sections.m_sections.back().m_left.size()); | ||||
// Recursively push nested args | // Recursively push nested args | ||||
sections.Push(arg); | sections.Push(arg); | ||||
} | } | ||||
ret += sections.ToString(); | ret += sections.ToString(); | ||||
// Result | |||||
ret += m_results.ToDescriptionString(); | |||||
// Examples | |||||
ret += m_examples.ToDescriptionString(); | |||||
return ret; | return ret; | ||||
} | } | ||||
std::string RPCArg::ToDescriptionString(const bool implicitly_required) const { | std::string RPCArg::ToDescriptionString(const bool implicitly_required) 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); | ||||
▲ Show 20 Lines • Show All 132 Lines • Show Last 20 Lines |