mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
doc: Properly report optional RPC args
This commit is contained in:
parent
fa09cb6086
commit
fad56f7dd6
2 changed files with 17 additions and 16 deletions
|
@ -405,12 +405,12 @@ struct Sections {
|
|||
left += push_name ? arg.ToStringObj(/*oneline=*/false) : arg.ToString(/*oneline=*/false);
|
||||
}
|
||||
left += ",";
|
||||
PushSection({left, arg.ToDescriptionString()});
|
||||
PushSection({left, arg.ToDescriptionString(/*is_named_arg=*/push_name)});
|
||||
break;
|
||||
}
|
||||
case RPCArg::Type::OBJ:
|
||||
case RPCArg::Type::OBJ_USER_KEYS: {
|
||||
const auto right = is_top_level_arg ? "" : arg.ToDescriptionString();
|
||||
const auto right = is_top_level_arg ? "" : arg.ToDescriptionString(/*is_named_arg=*/push_name);
|
||||
PushSection({indent + (push_name ? "\"" + arg.GetName() + "\": " : "") + "{", right});
|
||||
for (const auto& arg_inner : arg.m_inner) {
|
||||
Push(arg_inner, current_indent + 2, OuterType::OBJ);
|
||||
|
@ -425,7 +425,7 @@ struct Sections {
|
|||
auto left = indent;
|
||||
left += push_name ? "\"" + arg.GetName() + "\": " : "";
|
||||
left += "[";
|
||||
const auto right = is_top_level_arg ? "" : arg.ToDescriptionString();
|
||||
const auto right = is_top_level_arg ? "" : arg.ToDescriptionString(/*is_named_arg=*/push_name);
|
||||
PushSection({left, right});
|
||||
for (const auto& arg_inner : arg.m_inner) {
|
||||
Push(arg_inner, current_indent + 2, OuterType::ARR);
|
||||
|
@ -628,7 +628,7 @@ std::string RPCHelpMan::ToString() const
|
|||
if (i == 0) ret += "\nArguments:\n";
|
||||
|
||||
// Push named argument name and description
|
||||
sections.m_sections.emplace_back(::ToString(i + 1) + ". " + arg.GetFirstName(), arg.ToDescriptionString());
|
||||
sections.m_sections.emplace_back(::ToString(i + 1) + ". " + arg.GetFirstName(), arg.ToDescriptionString(/*is_named_arg=*/true));
|
||||
sections.m_max_pad = std::max(sections.m_max_pad, sections.m_sections.back().m_left.size());
|
||||
|
||||
// Recursively push nested args
|
||||
|
@ -722,7 +722,7 @@ bool RPCArg::IsOptional() const
|
|||
}
|
||||
}
|
||||
|
||||
std::string RPCArg::ToDescriptionString() const
|
||||
std::string RPCArg::ToDescriptionString(bool is_named_arg) const
|
||||
{
|
||||
std::string ret;
|
||||
ret += "(";
|
||||
|
@ -768,14 +768,12 @@ std::string RPCArg::ToDescriptionString() const
|
|||
ret += ", optional, default=" + std::get<RPCArg::Default>(m_fallback).write();
|
||||
} else {
|
||||
switch (std::get<RPCArg::Optional>(m_fallback)) {
|
||||
case RPCArg::Optional::OMITTED_NAMED_ARG: // Deprecated alias for OMITTED, can be removed
|
||||
case RPCArg::Optional::OMITTED: {
|
||||
if (is_named_arg) ret += ", optional"; // Default value is "null" in dicts. Otherwise,
|
||||
// nothing to do. Element is treated as if not present and has no default value
|
||||
break;
|
||||
}
|
||||
case RPCArg::Optional::OMITTED_NAMED_ARG: {
|
||||
ret += ", optional"; // Default value is "null"
|
||||
break;
|
||||
}
|
||||
case RPCArg::Optional::NO: {
|
||||
ret += ", required";
|
||||
break;
|
||||
|
|
|
@ -154,21 +154,24 @@ struct RPCArg {
|
|||
/** Required arg */
|
||||
NO,
|
||||
/**
|
||||
* The arg is optional for one of two reasons:
|
||||
*
|
||||
* Optional arg that is a named argument and has a default value of
|
||||
* `null`. When possible, the default value should be specified.
|
||||
*/
|
||||
OMITTED_NAMED_ARG,
|
||||
/**
|
||||
* `null`.
|
||||
*
|
||||
* Optional argument with default value omitted because they are
|
||||
* implicitly clear. That is, elements in an array or object may not
|
||||
* implicitly clear. That is, elements in an array may not
|
||||
* exist by default.
|
||||
* When possible, the default value should be specified.
|
||||
*/
|
||||
OMITTED,
|
||||
OMITTED_NAMED_ARG, // Deprecated alias for OMITTED, can be removed
|
||||
};
|
||||
/** Hint for default value */
|
||||
using DefaultHint = std::string;
|
||||
/** Default constant value */
|
||||
using Default = UniValue;
|
||||
using Fallback = std::variant<Optional, /* hint for default value */ DefaultHint, /* default constant value */ Default>;
|
||||
using Fallback = std::variant<Optional, DefaultHint, Default>;
|
||||
|
||||
const std::string m_names; //!< The name of the arg (can be empty for inner args, can contain multiple aliases separated by | for named request arguments)
|
||||
const Type m_type;
|
||||
|
@ -234,7 +237,7 @@ struct RPCArg {
|
|||
* Return the description string, including the argument type and whether
|
||||
* the argument is required.
|
||||
*/
|
||||
std::string ToDescriptionString() const;
|
||||
std::string ToDescriptionString(bool is_named_arg) const;
|
||||
};
|
||||
|
||||
struct RPCResult {
|
||||
|
|
Loading…
Add table
Reference in a new issue