mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-26 05:48:20 +01:00
rpc: Set RPCArg options with designated initializers
This commit is contained in:
@@ -137,6 +137,12 @@ enum class OuterType {
|
||||
NONE, // Only set on first recursion
|
||||
};
|
||||
|
||||
struct RPCArgOptions {
|
||||
std::string oneline_description{}; //!< Should be empty unless it is supposed to override the auto-generated summary line
|
||||
std::vector<std::string> type_str{}; //!< Should be empty unless it is supposed to override the auto-generated type strings. Vector length is either 0 or 2, m_opts.type_str.at(0) will override the type of the value in a key-value pair, m_opts.type_str.at(1) will override the type in the argument description.
|
||||
bool hidden{false}; //!< For testing only
|
||||
};
|
||||
|
||||
struct RPCArg {
|
||||
enum class Type {
|
||||
OBJ,
|
||||
@@ -169,30 +175,25 @@ struct RPCArg {
|
||||
using DefaultHint = std::string;
|
||||
using Default = UniValue;
|
||||
using Fallback = std::variant<Optional, /* hint for default value */ DefaultHint, /* default constant value */ 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;
|
||||
const bool m_hidden;
|
||||
const std::vector<RPCArg> m_inner; //!< Only used for arrays or dicts
|
||||
const Fallback m_fallback;
|
||||
const std::string m_description;
|
||||
const std::string m_oneline_description; //!< Should be empty unless it is supposed to override the auto-generated summary line
|
||||
const std::vector<std::string> m_type_str; //!< Should be empty unless it is supposed to override the auto-generated type strings. Vector length is either 0 or 2, m_type_str.at(0) will override the type of the value in a key-value pair, m_type_str.at(1) will override the type in the argument description.
|
||||
const RPCArgOptions m_opts;
|
||||
|
||||
RPCArg(
|
||||
const std::string name,
|
||||
const Type type,
|
||||
const Fallback fallback,
|
||||
const std::string description,
|
||||
const std::string oneline_description = "",
|
||||
const std::vector<std::string> type_str = {},
|
||||
const bool hidden = false)
|
||||
RPCArgOptions opts = {})
|
||||
: m_names{std::move(name)},
|
||||
m_type{std::move(type)},
|
||||
m_hidden{hidden},
|
||||
m_fallback{std::move(fallback)},
|
||||
m_description{std::move(description)},
|
||||
m_oneline_description{std::move(oneline_description)},
|
||||
m_type_str{std::move(type_str)}
|
||||
m_opts{std::move(opts)}
|
||||
{
|
||||
CHECK_NONFATAL(type != Type::ARR && type != Type::OBJ && type != Type::OBJ_USER_KEYS);
|
||||
}
|
||||
@@ -203,16 +204,13 @@ struct RPCArg {
|
||||
const Fallback fallback,
|
||||
const std::string description,
|
||||
const std::vector<RPCArg> inner,
|
||||
const std::string oneline_description = "",
|
||||
const std::vector<std::string> type_str = {})
|
||||
RPCArgOptions opts = {})
|
||||
: m_names{std::move(name)},
|
||||
m_type{std::move(type)},
|
||||
m_hidden{false},
|
||||
m_inner{std::move(inner)},
|
||||
m_fallback{std::move(fallback)},
|
||||
m_description{std::move(description)},
|
||||
m_oneline_description{std::move(oneline_description)},
|
||||
m_type_str{std::move(type_str)}
|
||||
m_opts{std::move(opts)}
|
||||
{
|
||||
CHECK_NONFATAL(type == Type::ARR || type == Type::OBJ || type == Type::OBJ_USER_KEYS);
|
||||
}
|
||||
@@ -227,7 +225,7 @@ struct RPCArg {
|
||||
|
||||
/**
|
||||
* Return the type string of the argument.
|
||||
* Set oneline to allow it to be overridden by a custom oneline type string (m_oneline_description).
|
||||
* Set oneline to allow it to be overridden by a custom oneline type string (m_opts.oneline_description).
|
||||
*/
|
||||
std::string ToString(bool oneline) const;
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user