Skip to content

Commit fabca42

Browse files
author
MarcoFalke
committed
RPCHelpMan: Add space after colons in extended description
Also, add doxygen comment to ToDescriptionString
1 parent fafd040 commit fabca42

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

src/rpc/util.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ struct Sections {
165165
if (outer_type == OuterType::NAMED_ARG) return; // Nothing more to do for non-recursive types on first recursion
166166
auto left = indent;
167167
if (arg.m_type_str.size() != 0 && outer_type == OuterType::OBJ) {
168-
left += "\"" + arg.m_name + "\":" + arg.m_type_str.at(0);
168+
left += "\"" + arg.m_name + "\": " + arg.m_type_str.at(0);
169169
} else {
170-
left += outer_type == OuterType::OBJ ? arg.ToStringObj() : arg.ToString();
170+
left += outer_type == OuterType::OBJ ? arg.ToStringObj(/* oneline */ false) : arg.ToString(/* oneline */ false);
171171
}
172172
left += ",";
173173
PushSection({left, arg.ToDescriptionString(/* implicitly_required */ outer_type == OuterType::ARR)});
@@ -188,7 +188,7 @@ struct Sections {
188188
}
189189
case RPCArg::Type::ARR: {
190190
auto left = indent;
191-
left += outer_type == OuterType::OBJ ? "\"" + arg.m_name + "\":" : "";
191+
left += outer_type == OuterType::OBJ ? "\"" + arg.m_name + "\": " : "";
192192
left += "[";
193193
const auto right = outer_type == OuterType::NAMED_ARG ? "" : arg.ToDescriptionString(/* implicitly_required */ outer_type == OuterType::ARR);
194194
PushSection({left, right});
@@ -345,9 +345,16 @@ std::string RPCArg::ToDescriptionString(const bool implicitly_required) const
345345
return ret;
346346
}
347347

348-
std::string RPCArg::ToStringObj() const
348+
std::string RPCArg::ToStringObj(const bool oneline) const
349349
{
350-
std::string res = "\"" + m_name + "\":";
350+
std::string res;
351+
res += "\"";
352+
res += m_name;
353+
if (oneline) {
354+
res += "\":";
355+
} else {
356+
res += "\": ";
357+
}
351358
switch (m_type) {
352359
case Type::STR:
353360
return res + "\"str\"";
@@ -362,7 +369,7 @@ std::string RPCArg::ToStringObj() const
362369
case Type::ARR:
363370
res += "[";
364371
for (const auto& i : m_inner) {
365-
res += i.ToString() + ",";
372+
res += i.ToString(oneline) + ",";
366373
}
367374
return res + "...]";
368375
case Type::OBJ:
@@ -393,7 +400,7 @@ std::string RPCArg::ToString(const bool oneline) const
393400
case Type::OBJ_USER_KEYS: {
394401
std::string res;
395402
for (size_t i = 0; i < m_inner.size();) {
396-
res += m_inner[i].ToStringObj();
403+
res += m_inner[i].ToStringObj(oneline);
397404
if (++i < m_inner.size()) res += ",";
398405
}
399406
if (m_type == Type::OBJ) {

src/rpc/util.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,21 @@ struct RPCArg {
8888
assert(type == Type::ARR || type == Type::OBJ);
8989
}
9090

91-
std::string ToString(bool oneline = false) const;
92-
std::string ToStringObj() const;
91+
/**
92+
* Return the type string of the argument.
93+
* Set oneline to allow it to be overrided by a custom oneline type string (m_oneline_description).
94+
*/
95+
std::string ToString(bool oneline) const;
96+
/**
97+
* Return the type string of the argument when it is in an object (dict).
98+
* Set oneline to get the oneline representation (less whitespace)
99+
*/
100+
std::string ToStringObj(bool oneline) const;
101+
/**
102+
* Return the description string, including the argument type and whether
103+
* the argument is required.
104+
* implicitly_required is set for arguments in an array, which are neither optional nor required.
105+
*/
93106
std::string ToDescriptionString(bool implicitly_required = false) const;
94107
};
95108

0 commit comments

Comments
 (0)