Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/util.h
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | enum class Type { | ||||
STR_HEX, | STR_HEX, | ||||
}; | }; | ||||
//! The name of the arg (can be empty for inner args) | //! The name of the arg (can be empty for inner args) | ||||
const std::string m_name; | const std::string m_name; | ||||
const Type m_type; | const Type m_type; | ||||
//! Only used for arrays or dicts | //! Only used for arrays or dicts | ||||
const std::vector<RPCArg> m_inner; | const std::vector<RPCArg> m_inner; | ||||
const bool m_optional; | const bool m_optional; | ||||
const std::string m_default_value; //!< Only used for optional args | |||||
const std::string m_description; | |||||
//! Should be empty unless it is supposed to override the auto-generated | //! Should be empty unless it is supposed to override the auto-generated | ||||
//! summary line | //! summary line | ||||
const std::string m_oneline_description; | const std::string m_oneline_description; | ||||
RPCArg(const std::string &name, const Type &type, const bool optional, | //! Should be empty unless it is supposed to override the | ||||
const std::string &oneline_description = "") | //! auto-generated type strings. Vector length is either 0 | ||||
: m_name{name}, m_type{type}, m_optional{optional}, | //! or 2, m_type_str.at(0) will override the type of the | ||||
m_oneline_description{oneline_description} { | //! value in a key-value pair, m_type_str.at(1) will | ||||
//! override the type in the argument description. | |||||
const std::vector<std::string> m_type_str; | |||||
RPCArg(const std::string &name, const Type &type, const bool opt, | |||||
const std::string &default_val, const std::string &description, | |||||
const std::string &oneline_description = "", | |||||
const std::vector<std::string> &type_str = {}) | |||||
: m_name{name}, m_type{type}, m_optional{opt}, | |||||
m_default_value{default_val}, m_description{description}, | |||||
m_oneline_description{oneline_description}, m_type_str{type_str} { | |||||
assert(type != Type::ARR && type != Type::OBJ); | assert(type != Type::ARR && type != Type::OBJ); | ||||
} | } | ||||
RPCArg(const std::string &name, const Type &type, | RPCArg(const std::string &name, const Type &type, const bool opt, | ||||
const std::vector<RPCArg> &inner, const bool optional, | const std::string &default_val, const std::string &description, | ||||
const std::string &oneline_description = "") | const std::vector<RPCArg> &inner, | ||||
: m_name{name}, m_type{type}, m_inner{inner}, m_optional{optional}, | const std::string &oneline_description = "", | ||||
m_oneline_description{oneline_description} { | const std::vector<std::string> &type_str = {}) | ||||
: m_name{name}, m_type{type}, m_inner{inner}, m_optional{opt}, | |||||
m_default_value{default_val}, m_description{description}, | |||||
m_oneline_description{oneline_description}, m_type_str{type_str} { | |||||
assert(type == Type::ARR || type == Type::OBJ); | assert(type == Type::ARR || type == Type::OBJ); | ||||
} | } | ||||
std::string ToString() const; | /** | ||||
* Return the type string of the argument. | |||||
private: | * Set oneline to allow it to be overrided by a custom oneline type string | ||||
std::string ToStringObj() const; | * (m_oneline_description). | ||||
*/ | |||||
std::string ToString(bool oneline) const; | |||||
/** | |||||
* Return the type string of the argument when it is in an object (dict). | |||||
* Set oneline to get the oneline representation (less whitespace) | |||||
*/ | |||||
std::string ToStringObj(bool oneline) const; | |||||
/** | |||||
* Return the description string, including the argument type and whether | |||||
* the argument is required. | |||||
* implicitly_required is set for arguments in an array, which are neither | |||||
* optional nor required. | |||||
*/ | |||||
std::string ToDescriptionString(bool implicitly_required = false) const; | |||||
}; | }; | ||||
class RPCHelpMan { | class RPCHelpMan { | ||||
public: | public: | ||||
RPCHelpMan(const std::string &name, const std::string &description, | RPCHelpMan(const std::string &name, const std::string &description, | ||||
const std::vector<RPCArg> &args) | const std::vector<RPCArg> &args) | ||||
: m_name{name}, m_description{description}, m_args{args} {} | : m_name{name}, m_description{description}, m_args{args} {} | ||||
Show All 9 Lines |